To combine/merge two maps in PHP, you can use array union operator (+
), which returns a new array containing all the elements from both arrays, with the values of the second array overwriting the values of the first array for any matching keys:
main.php157 chars7 lines
The output will be:
main.php73 chars6 lines
As you can see, the "key2"
value in $map2
overwrote the "key2"
value in $map1
.
gistlibby LogSnag