开发者

imploding array_keys from Facebook JSON data

开发者 https://www.devze.com 2023-01-25 09:55 出处:网络
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.

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

精彩评论

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