/ Published in: PHP
Create variable named PHP variables. Having dynamically named variables can be helpful when dealing with loops and arrays. For example instead of having seven if () statements for handling seven individual days of the week, you could reduce it to one if statement by doing a loop with seven iterations and dynamically create your variable names.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// create fifty (50) variable named variables named my_var1, my_var2... $name = "my_var"; for ($i = 0; $i < 50; $i++) { } echo $my_var3; // slightly more complex example to create a variably named array w/concatenation $name = "my_var"; for ($i = 1; $i <=5; ++$i) echo $my_var2_arr;
URL: http://www.justskins.com/forums/variable-in-variable-name-96140.html