ghostrider
ghostrider

Reputation: 5259

parse a json array inside a json array in php

I am having a json object $result

I do this:

$json = json_decode($result, true);

Here is the output if I use this:

var_dump($json)

is this:

array(15) { ["id"]=> int(1)  ["name"]=> array(16) { ... } }

If I do this:

echo $json['id'];
echo $json['name'];

The id is printed correctly : 1 But in the name this is printed: Array

How can I get that array and print it?

Upvotes: 0

Views: 54

Answers (1)

sybear
sybear

Reputation: 7784

Several ways:

print_r($json['name']);
var_dump($json['name']);

Or manual with preferred delimiter:

echo implode(", ", $json['name']);

However you should check the function responsible for making that JSON string, because you expect a string instead of array.

Upvotes: 1

Related Questions