Q:

Adding an element to the beginning of an array without changing other array keys

How can I add an element to the beginning of array without changing array key values in PHP?

A:

To keep numerical keys from being reindexed, you could simply add the arrays together.
Instead of:
array_unshift($arr1, $arr2)

try:
$arr1 = $arr2 + $arr1;

A:

If you use self-assigned (e.g. literal) keys, array_unshift() will do it.
If you use auto-generated (numeric) keys, how should that work? Use '-1' as the new first key?
EDIT:
Thank you to JasonS for pointing out an error in this answer.
ANY numeric key will be re-indexed by array_unshift(), no matter if it was auto-generated or self-assigned - if it's numeric, it'll get scrambled. See the link to the documentation above for details.

A:

Use array_unshift(). (As mentioned, it will keep your string keys intact, but not numeric keys).

