Lance
Lance

Reputation: 4820

Looping thru facebook API array

I have successfully gotten the info that I need from the facebook API. I wanted to get my favorite athletes and my favorite sports teams. My favorite sports teams are stored in a php array by default. It looks like this:

[favorite_teams] => Array
        (
            [0] => Array
                (
                    [id] => 39523792780
                    [name] => New York Yankees
                )

            [1] => Array
                (
                    [id] => 286845273454
                    [name] => New York Giants
                )

            [2] => Array
                (
                    [id] => 8725012666
                    [name] => Boston Celtics
                )

        )

But, when I try to loop through and display all of them, it doesn't quite work. Here is the code for looping through that I have attempted to do.

    $numba = count($user_profile['favorite_teams']);

    for($i = 0;$i < $numba;++$i)
    {
         echo $user_profile['favorite_teams']['$i']['name'];
    }

Any suggestions?

Upvotes: 0

Views: 362

Answers (1)

Knowledge Craving
Knowledge Craving

Reputation: 7993

It should be:-

$numba = count($user_profile['favorite_teams']);

for ($i = 0; $i < $numba; $i++)
{
    echo $user_profile['favorite_teams'][$i]['name'];
}

Hope it helps.

Upvotes: 2

Related Questions