开发者

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

开发者 https://www.devze.com 2023-03-17 17:58 出处:网络
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?

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

精彩评论

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