How to loop through JSON array using PHP

后端 未结 4 2054
终归单人心
终归单人心 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 06:58

    I'm not sure what exactly you want but I guess you want print it just for debugging right now. You can try with print_r($obj); and var_dump($obj); - they must print something, especially var_dump(). When you see the data, you can easily edit function a little bit, so you can do for instance print_r($obj->reviews) or print_r($obj['reviews']), depending if $obj is object or array.

提交回复
热议问题