[英]array_walk only leaving values?
I have this code: 我有这个代码:
array_walk(
array('foo' => 2, 'bar' => 5, ...),
function ($v, $k) { return $k . '=' . $v; }
);
But after this, all thats left is array(2, 5)
. 但在此之后,剩下的就是
array(2, 5)
。
Why is this the case and how do I get the expected result of array('foo=2', 'bar=5')
? 为什么会出现这种情况?如何获得
array('foo=2', 'bar=5')
的预期结果array('foo=2', 'bar=5')
?
Pass your value by reference, like 通过引用传递你的价值,比如
$rgData = array('foo' => 2, 'bar' => 5);
array_walk(
$rgData,
function (&$v, $k) { $v = $k . '=' . $v; }
);
Also note that referenced value itself should be changed (return is not necessary here, only $v
changing matters) 另请注意,引用值本身应该更改(此处不需要返回,只有
$v
更改事项)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.