hi, this must be dead simple:
i have a list "a,b,c" and i need to convert that to an array containing elements a, b and c.
i am trying this:
$list="a,b,c"; $array=array($list);
what should i be doing?!
thanx
use for statement to loop through each value and add them into an array with array_push() http://us2.php.net/manual/en/function.array-push.php
thanks for that, so is this the best way? seems a bit long-winded:
for ($i = 0; $i <= $substr_count($list, ","); $i++) { ; // some code to work out which element we're on }
If your list is actually a string containing comma delimited elements, then you should use [man]explode/man instead, e.g.
$list = "a,b,c"; $array = explode(',', $list);
tada 🙂
Yes! explode() is the function for me, thank you very much : )