【发布时间】:2014-06-03 05:10:12
【问题描述】:
我有一个多维数组,我正在搜索特定值。 如果找到这些值,我需要使用这些值提取索引(创建新数组)并删除所有其他值。
array_intersect 在 php 5.3 上运行良好,现在在 5.4 上它抱怨 注意:数组到字符串的转换。
我发现 array_intersect 在 5.4 上存在多维数组问题。 https://bugs.php.net/bug.php?id=60198
这是我正在搜索的 $options 数组
Array (
[index1] => html
[index2] => html
[index3] => slide
[index4] => tab
[index5] => Array
(
[0] => 123
)
)
适用于 php 5.3.x 的代码
$lookfor = array('slide', 'tab');
$found = array_intersect($options, $lookfor);
print_r($found);
Array
(
[index3] => slide
[index4] => tab
)
但在 5.4.x 中,这会引发上述错误。
请问还有什么方法可以在没有循环的情况下做到这一点。 并且没有抑制错误。
谢谢!
【问题讨论】:
-
为什么不能使用当前的代码?您应该以任何方式禁止显示给最终用户的所有错误,并且不要记录这些。
-
当你打字时,我编辑了我的帖子。我不想抑制错误。希望找到解决方案而不是通过@隐藏通知
-
是什么阻止你只使用循环?
-
@Charles,$options 数组有 200 多个选项,因此我宁愿不循环遍历所有选项
-
去做吧。然后使用 xdebug 或 xhprof 分析您的代码。我向你保证,仅仅循环一个包含 200 个元素的数组的行为在性能方面甚至不会是杯水车薪。你认为
array_intersect(以及下面的array_filter)会是什么?
标签: php multidimensional-array