PHP decode nested JSON PHP decode nested JSON json json

PHP decode nested JSON


Use json_decode():

$decoded = json_decode($json_string);$comments = $decoded->data[0]->comments->data;foreach($comments as $comment){   $name = $comment->from->name;   $message = $comment->message;   //do something with it}


You can use the json_decode function to convert it to array and then iterate over the array using foreach loop.

$array = json_decode($json, true);foreach($array as $key => $value){  // your code....}

The second option to json_decode is whether or not you want to convert it to an array.