2010-09-21 67 views
0

陣列:陣列輸出用於單個值

Array 
(
[2010091907] => Array 
    (
     [home] => Array 
      (
       [score] => Array 
        (
         [1] => 7 
         [2] => 17 
         [3] => 10 
         [4] => 7 
         [5] => 0 
         [T] => 41 
        ) 

       [abbr] => ATL 
       [to] => 2 
      ) 

如何將訪問縮寫和顯示它的值。這裏是我的PHP代碼:

 $json=json_decode($data,true); 

    foreach ($json as $key => $date) { 
     echo "Key: ".$key."; Value: ".$date."<br />"; 
     foreach ($date as $team) { 
      echo "Team: ".$team."<br />"; 

     } 
    } 

回答

1
echo $array[2010091907]['home']['abbr']; 

將輸出

ATL 

,如果你想只輸出SINGL值。在你的循環結構中,JochenJung得到了下面的修復。

1

應該$team['abbr']

在你內心的foreach()

0

嘗試this

foreach ($arr as $key => $date) { 
    echo "Key: ".$key."; Value: ".$date."<br />"; 
     foreach ($date as $team) { 
      echo "Team: ".$team['abbr']; 
     }  
}