TIL combining PHP arrays
POSTED ON:
First, there was array_merge
.
Then array_replace
.
Finally, the +
operator (union).
Since all 3 do similar thing, and the docs don’t quite describe the difference between them, here’s a nice image of it.
This visual:
(Via array_merge vs array_replace vs + (plus aka union) in PHP)
array_merge
andarray_replace
work just the same for Associative Arrays (key=>value arrays, or objects in JS), so they can be used interchangeably.
and
https://stackoverflow.com/questions/5394157/whats-the-difference-between-array-merge-and-array-array
Related TILs
Tagged: php