将索引放在数组上
我如何更改以下代码,以便键
<代码> $结果不会被[0],[1],...
覆盖而是按照自己的方式保持?
$result = array_map(function($key, $value) {
return preg_replace("/(".$_POST['keyword'].")/i", "<mark>$1</mark>", $value);
}, array_keys($result), $result);
How can I change the following code so the keys
of $result
will not get overwritten by [0], [1], ...
but instead be kept the way they were?
$result = array_map(function($key, $value) {
return preg_replace("/(".$_POST['keyword'].")/i", "<mark>$1</mark>", $value);
}, array_keys($result), $result);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
array_walk
( docs )而不是array_map
它将保留密钥:Use
array_walk
(docs) instead ofarray_map
it will preserve keys: