In the for loop I am trying to count the amount of flights in a nested array decoded from a JSON feed. Unfortunately it only shows 2 flights, when more flights are available. What am I doing wrong?
Json feed example from endpoint
{
"response": [
{
"flight": {
"number": "6204",
"iata_number": "HV6204",
"icao_number": "TRA6204"
}
},
{
"flight": {
"number": "7012",
"iata_number": "TB7012",
"icao_number": "JAF7012"
}
},
{
"flight": {
"number": "6652",
"iata_number": "HV6652",
"icao_number": "TRA6652"
}
},
{
"flight": {
"number": "1925",
"iata_number": "W61925",
"icao_number": "WZZ1925"
}
},
{
"flight": {
"number": "5075",
"iata_number": "W65075",
"icao_number": "WZZ5075"
}
},
{
"flight": {
"number": "4289",
"iata_number": "W64289",
"icao_number": "WZZ4289"
}
},
{
"flight": {
"number": "7861",
"iata_number": "W67861",
"icao_number": "WZZ7861"
}
},
{
"flight": {
"number": "3066",
"iata_number": "FR3066",
"icao_number": "RYR3066"
}
}
]
} .
The PHP code example
<?php
$url = 'https://api.endpoint'; // path to JSON file
$data = file_get_contents($url);
$flights = json_decode($data, true);
for($i=0; $i<=count($flights['response'][0]['flight']['iata_number']); $i++) {
echo "Flightnumber" . $flights['response'][$i]['flight']["iata_number"] . '<br/>';
}
?>
Any help is very appreciated