Re: Regarding variable reference

From: Date: Tue, 15 Jun 2004 16:13:51 +0000
Subject: Re: Regarding variable reference
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-188324@lists.php.net to get a copy of this message
Ulrik S. Kofod wrote:
balaji.ankem@wipro.com sagde:
Hi, I have variables called Cookie1 to Cookie35. I would like to print the values of Cookie1 to Cookie35 using for loop. Could anybody correct the below code to print the variables. =============================for($i=1;$i<34;$i++) { $x="Cookie".$i; if(isset($$x)) { echo "<p>$x:$$x</p>"; } }
for($i=1;$i<34;$i++) {
        $x="Cookie".$i;
        eval("\$y = \$$x;");
Why are you using eval? Eval is slow and is a hack... Just do: $y = $$x;
        if(isset($y))
        {
                echo "<p>$x:$y</p>";
        }
}
-- paperCrane <Justin Patrin>

« previous php.general (#188324) next »