PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I turn a string into an array?


Interchange between strings and arrays is very common in PHP even for use on websites and manipulating data to be sent, or sent, from the webpage.

To do this you can use the explode function, like this, passing the delimiter to explode on as the first argument and the string as the second:

<?php
$mystring 
"I,love,washing,up";
$myarray explode(",",$mystring);
print_r($myarray);
?>


Which gives us this:

Array
(
[0] => I
[1] => love
[2] => washing
[3] => up
)



More strings PHP Questions

What is the difference between join and implode in PHP?
How do I fetch the meta tags from a webpage using PHP?
How do you check if a variable is set or not in PHP?
How do I print the " in an echo statement?
How can I repeat a string variable several times?