note 48850 deleted from function.eval by tularis

From: Date: Sun, 09 Jan 2005 15:04:45 +0000
Subject: note 48850 deleted from function.eval by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82985@lists.php.net to get a copy of this message
Note Submitter: agilo3 at gmail dot com Reason: bad code ---- If you have a lot of variables like $var0, $var1, $var2, $var3, etc. and you want to keep your script small by creating a for-loop to add "$var" and "$i" together, you can use something like the following code: <?php $var0 = "zero"; $var1 = "one"; $var2 = "two"; $var3 = "three"; $var4 = "four"; $var5 = "five"; for ($i = 0; $i <= 5; $i++) eval("\$vars[] = \"\$var".$i."\";"); // print_r($vars); ?> As opposed to doing the following (and enlarging your script): <?php // Bad, bad, bad! $vars[] = $var0; $vars[] = $var1; $vars[] = $var2; $vars[] = $var3; $vars[] = $var4; $vars[] = $var5; ?> Hope this helps. - Agilo

« previous php.notes (#82985) next »