note 53960 modified in function.eval by betz
| From: | betz@php.net | Date: | Tue, 27 Sep 2005 14:25:08 +0000 |
| Subject: | note 53960 modified in function.eval by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95880@lists.php.net to get a copy of this message | ||
a cool way to use eval is to convert strings into variable names.
this is a subsitute for using arrays.
look at this code:
<?php
for($a=1; $a<=5; $a++){
eval("$"."variable".$a."=".$a.";");
}
?>
this will create variables called variable1, variable2, and so on, that are equal to 1, 2, and so
on.
i recently used this to help a friend make a Flash game that sent variables like that to PHP.
--was--
a cool way to use eval is to convert strings into variable names.
this is a subsitute for using arrays.
look at this code:
<?php
for($a=1; $a<=5; $a++){
eval("variable".$a."=".$a.";");
}
?>
this will create variables called variable1, variable2, and so on, that are equal to 1, 2, and so
on.
i recently used this to help a friend make a Flash game that sent variables like that to PHP.
http://php.net/manual/en/function.eval.php