The following SSCCE prints:
Array ( [0] => FLAT [1] => A [2] => B [3] => C [4] => D [5] => E [6] => F [7] => G [8] => H [9] => I [10] => J )
What I wanted:
What I wanted was to insert an element with a value of "flat" at the start of the array, i.e. I wanted "flat" to be inserted at index 0, and the rest of the elements should move right by one position to give free position for the insertion at the beginning of the array.
So I tried to use the union operator. source
What I got:
But what actually happened was that the first element of the array, "id", was over-written/replaced by the newly inserted element.
The question is that why is this happening, and what should I do to achieve what I need?
$array = array(
0 => "id",
1 => "A",
2 => "B",
3 => "C",
4 => "D",
5 => "E",
6 => "F",
7 => "G",
8 => "H",
9 => "I",
10 => "J"
);
$arrayNew = array("flat") + $array;
print_r($array_new);