开发者

imploding array_keys from Facebook JSON data

Need some help with the sample code provided the facebook. I can't get it to return a series of I开发者_JAVA技巧Ds that I need to run a sql query against.

   $friends = '{
   "data": [
      {
         "name": "Paul",
         "id": "12000"
      },
      {
         "name": "Bonnie",
         "id": "120310"
      },
      {
         "name": "Melissa",
         "id": "120944"
      },
      {
         "name": "Simon",
         "id": "125930"
      },
      {
         "name": "Anthony",
         "id": "120605"
      },
      {
         "name": "David",
         "id": "120733"
     }
   ]
}';

$obj = json_decode($friends);
print $obj->{'data'}[0]->{'name'};

I can return the "Paul"

what I want is to return all the id's using implode(array_keys($obj),",")

I am only getting data to return.

What I'd like to do is retrieve all the IDs separated by a comma.

Thanks!


Try implode-ing on the data key with array_map:

function get_id($o) {
   return $o->id;
}

implode(array_map('get_id', $obj->data),",")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜