|
Posted by Norman Peelman on 02/27/07 00:11
rog wrote:
> I have some variables, $unit1, $unit2 and $unit3, that I would like to read
> from a loop like this (or any other way):
>
> for($x=1;$x<=3;$x++)
> {
> $str='unit' . $x
> echo eval($str);
> }
>
> The debugger shows $str as '$unit1' but eval() gives a parse error.
> Can someone give a tip?
>
> Thanks,
> Roger
>
>
>
for($x=1;$x<=3;$x++)
{ // create variabls unit1, unit2, unit3...
${"unit$x"} = $x;
$str = "unit$x = ".${"unit$x"}.'<br>';
//echo "unit$x = ${"unit$x"}<br>"; // will work too...
}
echo $unit2;
output:
unit1 = 1
unit2 = 2
unit3 = 3
2
Norm
[Back to original message]
|