Order of Elements in Arrays in PHP
As you already know, in regular arrays, elements are arranged in a strict order because the position of each element determines its key. In associative arrays, we assign the keys ourselves, so the order of the elements does not matter.
For example, consider this associative array:
<?php
$arr = [1 => 'value1', 2 => 'value2', 3 => 'value3'];
echo $arr[1]; // will output 'value1'
echo $arr[2]; // will output 'value2'
echo $arr[3]; // will output 'value3'
?>
If you rearrange the elements of this array in an arbitrary order (of course, together with their keys), then nothing will change in the operation of our script:
<?php
$arr = [3 => 'value3', 1 => 'value1', 2 => 'value2'];
echo $arr[1]; // will output 'value1'
echo $arr[2]; // will output 'value2'
echo $arr[3]; // will output 'value3'
?>
In addition, numeric keys do not necessarily have to have all values without gaps. We can have arbitrary numbers and this will not cause any problems:
<?php
$arr = [7 => 'value1', 50 => 'value2', 23 => 'value3'];
?>
Check what is described on one of your associative arrays.