如何在“title”或“description”值中筛选具有特定关键字的多维数组,如下面的数据数组:
Array
(
[0] => Array
(
[id] => 873
[title] => Mark
[description] => John Doe Billy
[category] => Array
(
[id] => 52
[name] => Wall Art
)
)
[1] => Array
(
[id] => 266
[title] => Ninja Turle
[description] => Mark Doe
[category] => Array
(
[id] => 52
[name] => Wall Art
)
)
[2] => Array
(
[id] => 227
[title] => Red Rose
[description] => Billy Jean
[category] => Array
(
[id] => 52
[name] => Wall Art
)
)
)
以前我使用了下面的代码,它可以根据需要工作和显示,但同时我得到了错误消息“Notice:Array to string conversion”。
$search = "/mark/i";
$products = array_filter($data, function($a) use($search) {
return preg_grep($search, $a);
});
我是不是丢了密码?或者有更好的办法。
提前谢谢你