Source: stitcher.io

What does array do in PHP?

Category: PHP

If you enjoy reading my blog, you could consider supporting me on Patreon. The "plus" sign is a shorthand way of merging arrays, but there's a difference in how they are merged compared to using array_merge. Let's imagine these two arrays: Merging them using + would result in the following: While using array_merge, would result in this: What's happening here is that array_merge will override existing keys, while + will not. In other words: when a key exists in the first array, + will not merge an item with the same key from another array into the first one.

The same applies for textual keys: And finally, + also works with nested arrays: Using + will keep the original value, while array_merge would override it.
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