I’ve noticed recently in PHP you can do this.
$myNewArray = $oldArray + $someArray;
This looks completely different to anything I’ve seen before involving manipulating arrays in PHP.
How and why does it work? Are there any pitfalls?
I have recently started using it in some places where I may have used array_unshift() and array_merge().
When in doubt, consult the documentation. The behavior is different from array_merge: array_merge appends/overwrites,
+only appends.Example:
Output – as you see, array_merge overwrote the value from $a[‘foo’] with $b[‘foo’]; $a+$b did not: