有人可以向我解释为什么你不能传递密钥作为参考?
例如:
if(is_array($where)){
foreach($where as &$key => &$value){
$key = sec($key);
$value = sec($value);
}
unset($key, $value);
}
Run Code Online (Sandbox Code Playgroud)
抛出:
Fatal error: Key element cannot be a reference in linkstest.php on line 2
Run Code Online (Sandbox Code Playgroud)
我可以使用array_map做类似的事情吗?我想要做的就是迭代一个关联数组,并使用我的sec()函数转义键和值.
阵列图很难让我理解:
我已经尝试过很多关于array_map的东西,但是我无法直接对它进行操作.
使用数组映射比使用foreach循环获得任何性能优势吗?
我不喜欢foreach的是我无法直接对数组执行操作,并且必须处理创建临时数组并取消设置它们:
foreach($where as $key => $value){
$where[secure($key)] = secure($value);
}
Run Code Online (Sandbox Code Playgroud)
如果它在键中找到要转义的内容,添加新元素并保持未转义的元素,则可能会失败.
所以我坚持这样的事情?
$temparr = array();
foreach($where as $key => $value){
$temparr[secure($key)] = secure($value);
}
$where = $temparr;
unset($temparr);
Run Code Online (Sandbox Code Playgroud)
任何替代品?