PHP - convert comma separated values (not file) into array ?

joe.attaboy

New member
Use a foreach loop on the existing array:

$newarray = array();

foreach ($favilst as $item) {
array_push($newarray,$item)]
}

print_r($newarray);

You should see the array listing the way you want it.
 
Hello,
I'm trying to convert a string that contains comma separated values into array:
----------------------------------------------------------------------------------------------------------------
$dresult = mysql_query("SELECT * FROM devices WHERE device= '$serial' ");
while($row = mysql_fetch_array($dresult))
{
$favlist = array($row['Favourites']);
}
------------------------
cell contains values like "c34,f54,a22,e32"

print_r($favlist) gives out:

Array
(
[0] => c34,f54,a22,e32
)

and I would like to have it like this:

Array
(
[0] => c34
[1]=>f54
[2]=>a22
[3]=>e32
)

How do I do that?
 
Back
Top