79267313

Date: 2024-12-10 07:19:13
Score: 0.5
Natty:
Report link

PHP associative and indexed arrays are different.

Associative arrays uses named keys --- strings, to access the variable data. Your code generates an associative array, so using

var_dump($new_array[1]) // wont work
var_dump($new_array['ca']) // will work

Indexed arrays uses numeric values, just like a regular array would

Accessing your new array, we could:

foreach ($new_array as $key => $value) {
    var_dump($new_array[$key]);
}

I do not know if it would be useful but we can force an index array implementation using $array[] = ..

$new_new_array = [];
foreach ($new_array as $data) {
    $new_new_array[] = $data;
}
var_dump($new_new_array[1]); // this works

I can only manage to do this at the very end because your data processing requires the keys to be strings.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: lemon8de