0

i am trying to display array values return from facebook api. array is stored in $result below is my array

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => Ravi Shankar
                    [id] => 10206576743272319
                )

        )

    [paging] => Array
        (
            [next] => https://graph.facebook.com/v2.5/1705944052976370/friends?limit=25&offset=25&__after_id=enc_AdBV9ZBlJwwdjBL8iWeIAZBSxDqJO0gvQWS45qwBBg1X8tCbZAoj9Cz506ZCGuDnddOL07MZD
        )

    [summary] => Array
        (
            [total_count] => 4628
        )

)

i tried using foreach but confused

 foreach($result as $key=>$value){

    echo $key."-".$value."<br />";
    }

i want to display the result like below:

    name    id
    xxxx   123456
    yyyy   173453

2 Answers 2

1

Write your foreach loop as below:-

foreach($result['data'] as $key=>$value){
        echo $value['name'].'-'.$value['id']."<br>";           
}

Hope it will help you :)

Sign up to request clarification or add additional context in comments.

Comments

0

You need to use foreach in the $result["data"]:

foreach ($result["data"] as $friend) {
  echo "{$friend["id"]} => {$friend["name"]}";
}

The each $friend variable is an array, of this format:

Array
(
    [name] => Ravi Shankar
    [id] => 10206576743272319
)

Comments

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.