|
Posted by rog on 02/27/07 00:47
Thanks,
It looks like it's all about the {} operator or whatever it is.
Wish they were covered in the php docs.
:)
R
"Norman Peelman" <npeelman@cfl.rr.com> wrote in message
news:45e37722$0$24693$4c368faf@roadrunner.com...
> 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]
|