note 24534 added to language.variables.variable
| From: | thien_tmpNOSPAM at hotmail dot com | Date: | Tue, 20 Aug 2002 19:37:46 +0000 |
| Subject: | note 24534 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35264@lists.php.net to get a copy of this message | ||
You can also use variable variables and the string concat operator to generate suffixed (or
prefixed) variables based on a base name.
For instance, if you wanted to dynamically generate this series of variables:
base1_suffix1
base1_suffix2
base2_suffix1
base2_suffix2
base3_suffix1
base3_suffix2
You can do this:
$bases = array('base1', 'base2', 'base3');
$suffixes = array('suffix1', suffix2);
foreach($bases as $base) {
foreach($suffixes as $suffix) {
${$base.$suffix} = "whatever";
#...etc
}
}
--
http://www.php.net/manual/en/language.variables.variable.php
http://master.php.net/manage/user-notes.php?action=edit+24534
http://master.php.net/manage/user-notes.php?action=delete+24534
http://master.php.net/manage/user-notes.php?action=reject+24534