jeudi 26 mars 2015

Undefined index looping through json associative array in php


I'm having an issue with a json associative array. If I print_r this:



print_r ($boxscore['game']['home']['players'][0]['statistics']['hitting']['ab']);


It will return a result. But if I try to use a foreach loop through that array:



foreach ($boxscore['game']['home']['players'] as $home)


I get this error:


Severity: Notice


Message: Undefined index: players


I have several json associative arrays that work fine but I can't quite figure out why this one isn't working. Even weirder is I can go a few levels deeper than where I'm getting the error and print_r a value.





Aucun commentaire:

Enregistrer un commentaire