It's possible to define keys only for some of the array items
$array = [1, 2, "name"=>"Three", 4];
print_r($array);
Result
Array
(
[0] => 1
[1] => 2
[name] => Three
[2] => 4
)
If we set higher index manually, it will continue adding 1 to the max index
$array = [1, 2, 7=>"Three", 4];
print_r($array);
Result
Array
(
[0] => 1
[1] => 2
[7] => Three
[8] => 4
)
If we set higher index manually, it will continue adding 1 to the index
$array = [1, 2, 7=>"Three", 4=>"forth", 25];
print_r($array);
Result
Array
(
[0] => 1
[1] => 2
[7] => Three
[4] => forth
[8] => 25
)
Only integer and string values are allowed as array keys
$array = [
1 => "a",
"1" => "b",
"-1" => "-b",
'1.5' => "c",
true => "d",
];
print_r($array);
Result
Array
(
[1] => d
[-1] => -b
[1.5] => c
)