-1

I'm pulling data from a table in my database.

When I run var_dump($data) I get the following:

string(250) "{
    "Name": "Bobby Banks",
    "Manager": "Barry Banks"
},"

I'd like to grab the Manager value.

I have tried echo $data->Manager; and echo $data['Manager']; but no success.

4
  • 6
    $data = json_decode($data, true); echo $data['Name']; Commented May 23, 2018 at 10:37
  • @ka_lin this should be an answer. Commented May 23, 2018 at 10:39
  • @DanielJames I pretty sure it's a duplicate and wanted to avoid downvotes :) Commented May 23, 2018 at 10:40
  • 1
    Possible duplicate of Parse JSON string contents into PHP Array Commented May 23, 2018 at 10:44

1 Answer 1

1

Use the following:-

$jsonObject = json_decode($data, true);
echo $jsonObject['Manager'];

complete script:-

<?php

$stringJson = '{"Name": "Bobby Banks","Manager": "Barry Banks"}';
$json = json_decode($stringJson, true);

echo $json['Manager'];

?>

Output:-

Barry Banks
Sign up to request clarification or add additional context in comments.

3 Comments

Hi @nandal - this doesn't output anything, sadly :-( Can you show me the full script you're using and I can see this?
Hi @michaelmcgurk, I have updated the answer, see if it helps in understanding php json object handling.
Thank You, @nandal - it was a trailing comma on my JSON that was giving me the problem all along.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.