PHP变量名中的变量
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
// 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;
以上是关于PHP变量名中的变量的主要内容,如果未能解决你的问题,请参考以下文章