0

I can't access my json and would like to know where the error is.

$json = json_encode($data);
// string(1065) "[{"id":"test123","key":["one",...

Then I decode it to make it accessable via this command:

$json = json_decode($json, true);

// Output:
array(3) {
  [0]=>
  array(4) {
    ["id"]=>
    string(14) "test123"

When I want to echo it, it gives me:

echo $json[0];

Array to string conversion in

3
  • 4
    print_r($json[0]); Commented Oct 23, 2017 at 15:47
  • 4
    $json[0] is an array. You cannot echo an array. Commented Oct 23, 2017 at 15:48
  • 3
    echo $json[0]['id']; Commented Oct 23, 2017 at 15:50

1 Answer 1

5

Use print_r for array, echo is used to display a string that's why it's giving error.

print_r($json);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.