How to loop through JSON array using PHP

后端 未结 4 2048
终归单人心
终归单人心 2020-12-31 06:25

My PHP code:

$obj = json_decode($data);
print $obj->{\'name\'};

While it works for non-arrays, I can\'t for the life of me figure out h

4条回答
  •  情话喂你
    2020-12-31 07:01

    Here using objects example (to read reviews...raiting):

    $jsonObject = json_decode($data);
    foreach ($jsonObject->reviews as $data) {
        echo $data->rating;
    }
    

提交回复
热议问题