Problem reading a variable containing a list of numbers into an array. I have the following stored as a variable
$a='2,4,6,8';
// If I do $b=array(2,4,6,8); echo "$b[2]"; // returns 6
// but $c=array($a); echo "$c[2]"; // returns nothing ????
$a would be a varying number of integers in nonconsecutive order, stored in a db. I need to pull that into an array and be able to select one.
$a = '2,4,6,8'; $b = explode(",", $a);
$b=array(2,4,6,8); is actually
$b=array( "0" => "2", "1" => "4", "2" => "6", "3" => "8",);
so when echo $c[2] means echo the index of the array number "2", but not the value 2.
$a = array(1,2,3); $c = array($a);
echo 'c[0][2] = ' . $c[0][2];
would putput: 'c[0][2] = 3'