2011-10-04 59 views
0

有人可以幫助我來呼應[城市]值,並從以下陣列[國家]值:如何從這個數組回波值

<?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 
    ) 

    ) 
?> 

感謝。

+4

'回聲yourArray [0] [ 'CURRENT_LOCATION'] [ '城市'],yourArray [0] [ 'CURRENT_LOCATION'] [ '國家'];' – sdleihssirhc

回答

4

你有一個多維數組。你想試試這個:

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

像這樣:

echo $somearray[0]['current_location']['city']; 
echo $somearray[0]['current_location']['country']; 
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"; 
} 

所以,如果多於一個用戶出現在數據,你可以處理每一個。