First: My Problem
I’m trying to figure how these two log errors happened:
- Undefined array key 6
- Exception: count(): Argument #1 ($value) must be of type Countable|array, null given
Everything has been working fine for the last 6 months and still is, but these errors rised an eyebrow.
Second: Pertinent Code
$result = file_get_contents(“https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=” . “GEOCODE KEY”);
$output = json_decode($result, true);
if ($output[‘status’] == “OK”) {
for ($i = 0; $i <= count($output[‘results’][6]); $i++) {
…
Third: My Hypothesis and Question
Since the errors happened in the for loop the API return must have been a status OK to reach it, this means we should have the results but less than 6, the thing is, as far as I know (not much btw) the keys are different formats of the same place and what I cannot figure out is:
Can a localization be partially registered?
Thanks in advance, have a good one – https://www.youtube.com/watch?v=N5_mH44_QeY – Tell Me It’s a Nightmare (Kim Petras Cover)
I tried searching for the API answer details and looking for similar problems on this and other plataforms, both with no success :/
MAYCON AVNER BODANESE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.