How to use array_merge() Function In PHP
The array_merge() Function is used to merge two or more arrays into a single array. This function is used to merge the elements or values of two or more arrays together into a single array. The merging occurs in such a manner that the values of one array are appended at the end of the previous array.
Example 5: The array_merge() function merges elements of one or more than one array into one array.
PHP
<?php $array1 = array ( "GFG" , "stands" , "for" ); $array2 = array ( "Geeks" , "for" , "Geeks" ); $merge = array_merge ( $array1 , $array2 ); print_r( $merge ); ?> |
Output
Array ( [0] => GFG [1] => stands [2] => for [3] => Geeks [4] => for [5] => Geeks )
How to Insert a New Element in an Array in PHP ?
In PHP, an array is a type of data structure that allows us to store similar types of data under a single variable. The array is helpful to create a list of elements of similar types, which can be accessed using their index or key.
We can insert an element or item in an array using the below functions:
Table of Content
- Using array_unshift() Function
- Using array_push() Function
- Using array_merge() Function
- Using array_splice() Function