In this post I will demonstrate how to add arrays together without losing or reassigning the array keys in PHP. This is handy if you want to combine two arrays which have defined keys. For example lets say you have the following arrays:
If you use the php function array_merge the array keys will be renumbered like so:
As you can see the keys are be reindexed and start from 0. The solution is not to use any of the PHP inbuilt functions but simply use the plus symbol (+) to add both arrays together.
This gives us the desired output of: