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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners