|
Posted by shimmyshack on 02/26/07 21:04
On 26 Feb, 20:55, "rog" <jk!ttop5@mnpX$.net> wrote:
> Sorry, that should read:
>
> for($x=1;$x<=3;$x++)
> {
> $str='$unit' . $x
> echo eval($str);
>
> }
>
> Still doesn't work.
>
> Roger
>
> "rog" <jk!ttop5@mnpX$.net> wrote in message
>
> news:b56dnVxMKbsi1X7YnZ2dnUVZ_vmqnZ2d@comcast.com...
>
> >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
you could do this:
<?php
$unit1 = '123';
$unit2 = '231';
$unit3 = '321';
for($x=1;$x<=3;$x++)
{
echo ${'unit' . $x} . "\n<br />";
}
?>
Navigation:
[Reply to this message]
|