I'm trying to parse data from an TV Shows API, but I'm having trouble figuring out how to get the index numbers.
Example:
{
"data": {
"0": {
"1": {
"param1": "value1",
"param2": "warning",
}
},
"1": {
"1": {
"param1": "value1",
"param2": "value2",
},
"2": {
"param1": "value1",
"param2": "warning",
},
"3": {
"param1": "value1",
"param2": "warning",
},
}
}
}
The "params" and "values" I'm able to get just fine, but I can't 'echo' the index numbers.
This is how I'm trying to do it:
$string = file_get_contents(api);
$json_a = json_decode($string, true);
foreach ($json_a['data'] as $seasons) {
foreach ($seasons as $episodes) {
if ($episodes['param2']=="warning") {
// echo index number of season
// echo index number of episode
}
}
}
I believe I've read that using foreach I'm not able to get the index numbers? If so, what would be the solution?
I tried 'manually' incrementing variables for season number and episodes, but index numbers may vary. They may not be sequential and some start with index "1" instead of "0".