开发者

Is there any JSON find operation available to use in PHP?

Is there an开发者_如何学运维y find function available to use with PHP?

I mean if I want to fetch all records whose category = 'red', is it possible?

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"}]

now I want to retrieve all records whose colour = red , then can I perform this operation or not?


you could try array_filter


$arr = json_decode($str, true);
foreach ($arr as $row) {
    if ($row['colour'] == 'red') {
        echo $row['id'];
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜