I've managed to decode and echo a JSON feed. After running this command
print_r(json_decode($data,true));
this is what I see on the screen:
Array
(
[sportId] => 29
[last] => 96466864
[league] => Array
(
[0] => Array
(
[id] => 1980
[events] => Array
(
[0] => Array
(
[id] => 667177156
[starts] => 2016-11-26T15:00:00Z
[home] => Hull City
[away] => W.B.A
[rotNum] => 2504
[liveStatus] => 1
[status] => O
[parlayRestriction] => 2
)
[1] => Array
(
[id] => 672139467
[starts] => 2016-12-10T15:00:00Z
[home] => Hull City
[away] => Crystal Palace
[rotNum] => 2510
[liveStatus] => 1
[status] => O
[parlayRestriction] => 2
)
[2] => Array
(
[id] => 676973849
[starts] => 2016-12-26T15:00:00Z
[home] => Burnley
[away] => Middlesbrough
[rotNum] => 2519
[liveStatus] => 1
[status] => O
[parlayRestriction] => 2
)
)
)
)
)
I need to be able to use foreach to go through each [events] in this associative array, and to be able to get the result such as this:
Hull City v W.B.A.
Hull City v Crystal Palace
Burnley v Middlesbrough
I think everything is already parsed correctly and now it's just a matter of using the correct syntax to echo the result from the associative array, which I cannot do myself.
json_decodedoes. now, you just got a plain old, boring, simple array. containing nested arrays. up to the array called$decoded['league'][0]['events'], over which you have to iterate. and then, each of those items is an array itself, which you can use like every other array. as in:$line['home']