adam
adam

Reputation: 3

how to loop through the structure that facebook returns

so I'm writing a facebook app in PHP and I'm not really sure how to loop through and get the data out of what facebook returns. Here's an example where it only returns one:

object(stdClass)#1 (1) {
  ["data"]=>
  array(1) {
    [0]=>
    object(stdClass)#2 (4) {
      ["name"]=>
      string(28) "Naruto Shippuden Episode 216"
      ["access_token"]=>
      string(97) "249129248435706|2f30355a536c4947ec32f522.1-1117572370|181703111883131|JYPPUX4rupaiWzJoZaD2r7jI1E4"
      ["category"]=>
      string(7) "Tv show"
      ["id"]=>
      string(15) "181703111883131"
    }
  }
}

Any ideas on how to loop through that and pull out the data in PHP? Thanks!

Upvotes: 0

Views: 518

Answers (1)

zerkms
zerkms

Reputation: 254926

foreach ($object->data as $nested_object) {
    echo $nested_object->name;
    echo $nested_object->category;
    ...
}

Upvotes: 1

Related Questions