Skip to content
Advertisement

Foreach array inside of array

I have a JSON data that looks like this (link for full response here https://pastebin.com/LG2F9Vrw)

"data": [ { "matchId": 1653309, "personId": 1141434, "teamId": 89736, "competitors": [ { "teamCode": "SHC", "website": "", } ] },

There’s an array of ['data'] that I’m using with foreach to give me game statistics. There’s now a second array inside of the ['data'] array. I’mn trying to get the ['teamCode'] string to print but I can’t work out how to do it.

I’ve done my best following tutorials online.

JavaScript

There are other areas where I’m using print $item['sFieldGoalsPercentage']; but that’s coming under the first foreach.

Thanks!

Advertisement

Answer

this is simple code how to retreive ['teamCode'] you want (test link):

JavaScript

this is the output:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement