1

How do I display the data->name?

{
   "data": [
      {
         "name": "Aasdada",
         "category": "asdasd",
         "id": "2342342342",
         "created_time": "2012-11-28T03:56:00+0000"
      }
   ],
   "paging": {
      "next": "https://graph.facebook.com/&limit=5000&offset=5000&__after_id=12312"
   }
}

I tried this but nothing comes out:

$user = json_decode(file_get_contents($graph_url), true);
echo("Hello " . $user->data->name);

//also tried this
echo("Hello " . $user[data]); //did not echo anything
echo("Hello " . $user->data[0]->name); //did not echo anything

$user->data[0]['name'] //still no luck

What could be the problem? Anyways my code works with data that is not in array.

I'm just trying to make a simple if user liked page or not. If data has no contents it means the user has not liked the page. If it has data then it means the user has liked the page.

--edit--

So tried this out:

array(2) { ["data"]=> array(1) { [0]=> array(4) { ["name"]=> string(28) "Aasdda" ["category"]=> string(5) "asdad" ["id"]=> string(15) "3123123123" ["created_time"]=> string(24) "2012-11-28T03:56:00+0000" } } ["paging"]=> array(1) { ["next"]=> string(245) "https://graph.facebook.com/100023123123" } }

2 Answers 2

2

Try:

$user['data']['0']['name']
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

 $user->data[0]['name']

2 Comments

Hello didn't echo anything.
I can see by your output that sinister frogs should be correct.

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.