2017-03-12 194 views
0

我使用的API連接到第三方網站,其返回的結果如下:從數組中獲取數組的值?

stdClass Object 
(
    [timeFrameStart] => 2017-03-11 
    [timeFrameEnd] => 2017-03-12 
    [count] => 1 
    [fixtures] => Array 
     (
      [0] => stdClass Object 
       (
        [date] => 2017-03-11T15:00:00Z 
        [status] => FINISHED 
        [matchday] => 37 
        [homeTeamName] => Home Team 
        [awayTeamName] => Away Team 
        [result] => stdClass Object 
         (
          [goalsHomeTeam] => 0 
          [goalsAwayTeam] => 0 
         ) 

       ) 

     ) 

) 

我可以用得到球隊的名字:

foreach($details->fixtures as $record) { 
    echo $record->homeTeamName; 
} 

但是我似乎無法瞭解如何從結果數組中獲取goalHomeTeam/goalsAwayTeam值。

+0

foreach($ details-> fixtures as $ record){ echo $ record-> result-> goalsHomeTeam; } – cornelb

回答

1

嘗試:

foreach($details->fixtures as $record) { 
    echo $record->homeTeamName . '<br />'; 
    echo $record->result->goalsHomeTeam . '<br />'; 
    echo $record->result->goalsAwayTeam . '<br />'; 
} 

希望這有助於!

+0

就是這樣。我早些時候嘗試過,但得到了錯誤......很顯然,有一件事給了我一個錯誤!謝謝。 – BN83

+0

@ BN83很高興我能幫到你。如果這回答您的問題,請您將其標記爲正確。 –

+0

打算,只需等待就可以標記它。謝謝 – BN83