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'];
}
}
精彩评论