A foreach
loop may be the approach you're looking for.
For example, this code would output the years for each season in your JSON data, regardless of how many seasons there were:
//Get the page
$str = file_get_contents('http://myjsonurl.here/');
$jsonarray = json_decode($str, true);
foreach($jsonarray['season_history'] as $season) {
echo $season[0] . PHP_EOL;
}
Alternatively, if you just need to know the number of seasons, this would be a solution:
//Get the page
$str = file_get_contents('http://myjsonurl.here/');
$jsonarray = json_decode($str, true);
$numberOfSeasons = count($jsonarray['season_history']);
You could combine that with a for
loop as well, if you wanted:
for($i = 0; $i < $numberOfSeasons; $i++) {
echo $jsonarray['season_history'][$i][0];
}