doushi2902 2015-04-15 18:10
浏览 336
已采纳

使用Facebook Graph Api获取数据

I am trying to get all the facebook group members ids with facebook php sdk, I am getting an array, and can't get out of the array with only ids.

Here is my array:

Array
(
[data] => Array
    (
        [0] => stdClass Object
            (
                [name] => Name Surname
                [administrator] => 
                [id] => 655330041265756
            )

        [1] => stdClass Object
            (
                [name] => Name Surname2
                [administrator] => 
                [id] => 10206563909924840
            )

        [2] => stdClass Object
            (
                [name] => Name Surname3
                [administrator] => 
                [id] => 1035931373098451
            )

I am trying to export only [id], how is this possible?

  • 写回答

1条回答 默认 最新

  • drjtua5953 2015-04-15 18:19
    关注

    Just a simple foreach can be used to iterate through the array and extract the id from each object.

    foreach ($array as $key=>$value) {
        echo $value->id;
    }
    

    Edit: If you want to assign the ids to an array, use the following code:

    foreach ($array as $key=>$value) {
         $idArray[] = $value->id;
    }
    

    Where $idArray is your array of ids.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?