![](/img/trans.png)
[英]How does the variable name $array work out in PHP though it's a keyword and built-in function?
[英]PHP built-in function to assign each element of an array to a variable, does it exist?
例如:
$array = array('f', 'b');
assign($foo, $bar, $array);
// now $foo = 'f' and $bar = 'b'
PHP语言中是否存在类似的内容? 我以前从来不需要这样的东西,也找不到能做到这一点的东西。
我只是想确保自己写函数之前-我不想写语言中已经存在的东西。
非常接近PHP的extract()函数。
但是,您需要指定var名称,因为它们是数组中每个值的键。
$array = array('foo' => 'f', 'bar' => 'b');
extract($array);
// now $foo = 'f' and $bar = 'b'
您可以使用php的list()
函数
$array = array('f', 'b');
list($foo, $bar) = $array;
现在它是
$foo = 'f' and $bar = 'b';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.