Home >Backend Development >PHP Tutorial >PHP uses the key name in the array as the variable name and the key value as the variable_PHP tutorial
This article will introduce you to how PHP uses the key names in the array as variable names and the key values as variables. I hope this tutorial will be helpful to all students.
代码如下 | 复制代码 |
/* php 把数组中的键名所为变量名键值作为变量 */ $arr=array('a'=>1,'b'=>2,'c'=>3,'d'=>5,'e'=>6); //方法一,使用foreach循环实现 foreach($arr as $key=>$value){ $$key=$value; } echo $a; //方法二,其实php早就已经实现了这个功能extract extract($arr); echo $a; |