I’m trying to specifically pull the current number of outs from ESPN’s MLB API; since this has live data and you could be looking at any time, I put an example pull of data here: https://pastebin.com/JBY29dHM
If I look at that JSON through the JSON Parser here: https://jsonformatter.org/json-parser
Then what I’m trying to use PHP to obtain is the information located at [object > events > 9 > competitions > 0 > outsText]
(If you want to see the live API, you can find it here: http://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard)
First, I grab each individual game for processing with: foreach ($scores["events"] as $event) {
, which should effectively ‘point’ to [object > events > 9]
in the example JSON. And if I use:
$quarter = $event['status']['type']['detail'];
then it does effectively get the data at [object > events > 9 > status > type > detail]
, so it would seem $event
does contain the data I think the does at the level of the JSON that I’m expecting. However, if I try to access ‘competitions’ as follows:
$time = $event['competitons'][0]['outsText'];
then I get an undefined array key error where I’m expecting “0 outs” to be.
I did a var_dump of what $event is at the time of the error, and put the output of that into a pastebin here, but it has so much data it’s probably going to be hard to parse: https://pastebin.com/preAVLgp
Then for completions sake, here’s the entire PHP script in case you need to see all of it more in context: https://pastebin.com/GGpv3tFk