<?php
$array = '[{
"GameId": 53614,
"Season": 2018,
"SeasonType": 1,
"Day": "2018-09-28T00:00:00",
"DateTime": "2018-09-28T14:10:00",
"Status": "InProgress",
"AwayTeamId": 16,
"HomeTeamId": 20,
"AwayTeamName": "CHW",
"HomeTeamName": "MIN",
"GlobalGameId": 10053614,
"GlobalAwayTeamId": 10000016,
"GlobalHomeTeamId": 10000020,
"PregameOdds": [{
"GameOddId": 509945,
"Sportsbook": "BetDSI",
"GameId": 53614,
"Created": "2018-09-28T14:12:36",
"Updated": "2018-09-28T16:27:12",
"HomeMoneyLine": -185,
"AwayMoneyLine": 169,
"HomePointSpread": -1.7,
"AwayPointSpread": 1.7,
"HomePointSpreadPayout": 140,
"AwayPointSpreadPayout": -163,
"OverUnder": 9.0,
"OverPayout": -123,
"UnderPayout": -123
}],
"LiveOdds": []
}]';
$array = (array)json_decode($array);
//Este seria si tuvieses mas de un indice dentro de tu json array
foreach($array as $clave => $valor){
echo 'GameId = '.$valor->GameId.'<br>';
echo 'Season = '.$valor->Season.'<br>';
echo 'DateTime = '.$valor->DateTime.'<br><br>';
if(is_array($valor->PregameOdds)){
foreach($valor->PregameOdds as $clave2 => $valor2){
echo 'GameOddId = '.$valor2->GameOddId.'<br>';
echo 'Sportsbook = '.$valor2->Sportsbook.'<br>';
echo 'Created = '.$valor2->Created.'<br><br>';
};
};
};
//Este seria si siempre accederias al primer indice de tu array
echo 'GameId = '.$array[0]->GameId.'<br>';
echo 'Season = '.$array[0]->Season.'<br>';
echo 'DateTime = '.$array[0]->DateTime.'<br>';
?>
David Leonardo Molina Ruiz Dav
- 4.1k
- 1
- 9
- 25