there's one example of var-of-vars along with arrays below my rant

<rant>
var-of-var is almost always an evil thing.  there are some
rare instances where they're necessary, but i assure you
that your script would be MUCH cleaner and easier to modify
in the future if you used a simple array.

compare: $value = $form[$temp . $i];
to: eval('$valueofsize = $'. $temp . $i .';');
</rant>

$form['size1'] = "hey";
$form['size2'] = "there";

$size1 = "hey";
$size2 = "there";
$loopcounter = 2;

while ($i++ < $loopcounter) {
        $temp = "size";
        eval('$valueofsize = $'. $temp . $i .';');
        print $valueofsize;
        print $form[$temp . $i];
}

----------------
Scott Hurring - Internet Programmer
GraphicType Services
tel: 973.667.9486
web: http://www.graphictype.com/
pgp: http://graphictype.com/scott/pgp.txt
----------------


> -----Original Message-----
> From: Mike Krisher [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 17, 2002 11:12 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] variable variables
>
>
> I can not wrap my head around variable variables today, not awake yet or
> something.
>
> For instance I trying something like this:
>
> while ($i<$loopcounter) {
>       $temp = "size";
>       $valueofsize = $$temp$i;
>       $i++;
> }
>
> this doesn't work obviously, $valueofsize ends up with a literal value of
> "$size1". But I need it to equal the value of a variable named $size1. Do I
> need to use a eval() or something?
>
> Thanks in advance,
>  Michael Krisher
>   [EMAIL PROTECTED]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to