是否有可用于PHP的查找功能?
我的意思是,如果我想获取category ='red'的所有记录,是否可能?
e.g。
[{"id":1,"name":"a","colour":"red"},{"id":2,"name":"b","colour":"red"},{"id":3,"name":"c","colour":"green"},{"id":4,"name":"d","colour":"green"}]
现在我想检索 color = red 的所有记录,然后我可以执行此操作吗?
答案 0 :(得分:1)
您可以尝试array_filter
答案 1 :(得分:0)
$arr = json_decode($str, true);
foreach ($arr as $row) {
if ($row['colour'] == 'red') {
echo $row['id'];
}
}