如何回显此数组中的值

时间:2011-10-04 19:36:14

标签: php arrays

有人可以帮我回复以下数组中的[city]值和[country]值:

<?php
    Array
    (
    [0] => Array
    (
    [uid] => 123456789
    [name] => First Last Name
    [current_location] => Array
    (
    [city] => New York
    [state] => New York
    [country] => United States
    [zip] => 
    [id] => 123456789
    [name] => New York, New York
    )

    [profile_url] => http://www.facebook.com/username
    )

    ) 
?>

感谢。

3 个答案:

答案 0 :(得分:4)

你有一个多维数组。你想试试这个:

echo $arr[0]['current_location']['city'];
echo $arr[0]['current_location']['country'];

答案 1 :(得分:1)

像这样:

echo $somearray[0]['current_location']['city'];
echo $somearray[0]['current_location']['country'];

答案 2 :(得分:0)

正如已经指出的那样,你有一个多维数组 - 换句话说就是一个数组中的数组。

这种数据通常是这样访问的:

foreach ($yourArray as $data) {
    $locationData = $data['current_location'];

    echo "user id " . $data['uid'] . "\n";
    echo " - city " . $locationData['city'] . "\n";
    echo " - country " . $locationData['country'] . "\n";
}

因此,如果数据中出现多个用户,则可以处理每个用户。