note 24534 deleted from language.variables.variable by cmb
| From: | cmb@php.net | Date: | Sun, 12 Jan 2020 08:24:26 +0000 |
| Subject: | note 24534 deleted from language.variables.variable by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213858@lists.php.net to get a copy of this message | ||
Note Submitter: thien_tmpNOSPAM at hotmail dot com
----
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:
<?php
$bases = array('base1', 'base2', 'base3');
$suffixes = array('suffix1', suffix2);
foreach($bases as $base) {
foreach($suffixes as $suffix) {
${$base.$suffix} = "whatever";
#...etc
}
}
?>