Skip to content
Advertisement

PHP append one array to another (not array_push or +)

How to append one array to another without comparing their keys?

JavaScript

At the end it should be: Array( [0]=>a [1]=>b [2]=>c [3]=>d ) If I use something like [] or array_push, it will cause one of these results:

JavaScript

It just should be something, doing this, but in a more elegant way:

JavaScript

Advertisement

Answer

array_merge is the elegant way:

JavaScript

Doing something like:

JavaScript

Will not work, because the + operator does not actually merge them. If they $a has the same keys as $b, it won’t do anything.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement