Category: PHP

If you enjoy reading my blog, you could consider supporting me on Patreon. If you want to join two multidimensional arrays in PHP, you should still use array_merge, and not array_merge_recursive.

Let's first explain what array_merge_recursive does, take for example these two arrays: Using array_merge_recursive will result in the following: Instead over overriding the original key value, array_merge_recursive created an array, with the original and new value both in it. While that looks strange in this simply example, it's actually more useful in cases where one of the values already is an array, and you want to merge another item in that array, instead of overriding it. In this case, array_merge_recursive will yield the same result as the first example: it takes the value from the $second array, and appends it to the value in the $first array, which already was an array itself.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners