|
Posted by J.O. Aho on 01/09/07 12:47
Geoff Berrow wrote:
> Message-ID: <dfn6q25mhhkts44htptacnu5rmkbcnrq3p@4ax.com> from Onideus
> Mad Hatter contained the following:
>
>> In PHP...how you do you have a variable, array variable?
>
> Funnily enough, I was doing exactly the same thing yesterday. or
> rather, finding out you can't do it. As JO Aho points out, the way to
> go is multidimensional arrays.
It's possible to do it, but multidimensional arrays are easier, had to
experiment a bit myself, but here is an example that works:
<?PHP
/* Three arrays */
$var_1=array("one","two","three");
$var_2=array("four","five","six");
$var_3=array("seven","eight","nine");
/* here we tell we want array var_2 */
$i=2;
/* here we tell we want the third cell (first=0) */
$pos=2;
/* here we create the variable name */
$variabletouse="var_$i";
/* here we copy the contents of the variable to a temp variable */
$temp= $$variabletouse;
/* here we can pick out the value */
echo $temp[$pos]; //should give six
?>
while in a multidimensional it had been done with
<?PHP
/* One array */
$array=array(
array("one","two","three"),
array("four","five","six"),
array("seven","eight","nine")
);
/* here we tell we want array var_2 */
$i=2;
/* here we tell we want the third cell (first=0) */
$pos=2;
/* here we pick the value */
echo $array[$i][$pos];
?>
--
//Aho
Navigation:
[Reply to this message]
|