array_merge() function is used to merge one or more than one arrays into a single resultant array.
Main Features of array_merge() Function
- It can merge more than two functions.
- Arrays may have a different number of elements.
- Elements having the same key are overwritten by the last elements.
- We can pass one, two or many arrays to merge.
- In case of a single array is passed to merge and it is an Indexed array, The output array is having index starts from zero(0).
<?php $marval_heros = ['Iron Man','Captain America','Hulk','Spidar Man']; $dc_heros = ['Bat Man','Super Man']; $indian_heros = ['Kriss','Chitthi','Shaktimaan']; //merge all super hero array $all_super_heros = array_merge($marval_heros,$dc_heros,$indian_heros); print_r($all_super_heros); $all_marvel_heros = array_merge($marval_heros); print_r($all_marvel_heros); ?>
The output of Above code samples:
(1) When $marvel_heros are merged only Array (  => Iron Man  => Captain America  => Hulk  => Spidar Man ) (2) When all are merged Array (  => Iron Man  => Captain America  => Hulk  => Spidar Man  => Bat Man  => Super Man  => Kriss  => Chitthi  => Shaktimaan )