PHP array_merge() Function Last Updated : 22 Jul, 2022 Comments Improve Suggest changes Like Article Like Report The array_merge() function is an inbuilt function in PHP that is used to merge two or more arrays into a single array. This function merges the elements or values of two or more arrays together to make 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. The function takes the list of arrays separated by commas as a parameter that is needed to be merged and returns a new array with merged values of arrays passed in the parameter. Syntax: array array_merge(array ...$arrays) Parameters: This parameter holds the array list that needs to merge to make a single array. Return Value: This function returns the merged array and returns empty array id parameter array is not given. Note: In the 7.4.0 version, this function can work without parameters but formerly, at least one parameter is required for this function. Example 1: PHP <?php $arr1 = array(5, 10, 15, 20); $arr2 = array(11, 12, 13, 14); $arr = array_merge($arr1, $arr2); var_dump($arr); ?> Output: array(8) { [0] => int(5) [1] => int(10) [2] => int(15) [3] => int(20) [4] => int(11) [5] => int(12) [6] => int(13) [7] => int(14) } Example 2: PHP <?php $arr1 = array( 'Geeks' => "HTML", 'GFG' => "CSS", 'Geek' => "JavaScript", 'G4G' => "PHP" ); $arr2 = array( 'Geeks' => "CPP", 'G4G' => "Java", 'Geek' => "Python", 'GeeksforGeeks' => "DSA" ); $arr = array_merge($arr1, $arr2); var_dump($arr); ?> Output: array(5) { ["Geeks"] => string(3) "CPP" ["GFG"] => string(3) "CSS" ["Geek"] => string(6) "Python" ["G4G"] => string(4) "Java" ["GeeksforGeeks"] => string(3) "DSA" } Reference: https://www.php.net/manual/en/function.array-merge.php Comment More infoAdvertise with us Next Article PHP array_merge() Function V vkash8574 Follow Improve Article Tags : Web Technologies PHP PHP-array PHP-function Similar Reads PHP | array_map() Function The array_map() is an inbuilt function in PHP and it helps to modify all elements one or more arrays according to some user-defined condition in an easy manner. It basically, sends each of the elements of an array to a user-defined function and returns an array with new values as modified by that fu 2 min read PHP array() Function The array() function is an inbuilt function in PHP which is used to create an array. There are three types of array in PHP: Indexed array: The array which contains numeric index. Syntax: array( val1, val2, val3, ... ) Associative array: The array which contains name as keys. Syntax: array( key=>v 2 min read PHP array_intersect() Function This builtin function of PHP is used to compute the intersection of two or more arrays. The function is used to compare the values of two or more arrays and returns the matches. The function prints only those elements of the first array that are present in all other arrays. Syntax: array array_inter 2 min read PHP Array Functions Arrays are one of the fundamental data structures in PHP. They are widely used to store multiple values in a single variable and can store different types of data, such as strings, integers, and even other arrays. PHP offers a large set of built-in functions to perform various operations on arrays. 7 min read PHP array_merge_recursive() Function The array_merge_recursive() is an inbuilt function in PHP and is used to merge two or more arrays into a single array recursively. 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 arra 3 min read PHP array_pad() Function The array_pad() is a builtin function in PHP and is used to pad a value fixed number of time onto an array. This function inserts an element specified number of times into an array either at front or back. Syntax: array array_pad($input_array, $input_size, $values) Parameters: This function accepts 3 min read PHP | DsSet merge() Function The Ds\Set::merge() function is an inbuilt function in PHP which returns a set after adding all given values to the set. Syntax: Ds\Set public Ds\Set::merge ( mixed $values ) Parameters: This function accepts single parameter $values which holds the elements. Return Value: This function returns the 1 min read PHP array_intersect_key() Function This builtin function of PHP is used to compute the intersection of two or more arrays. The function is different from array_intersect() and array_intersect_assoc() in a way that it uses the keys for the comparison and returns the matching key elements. The function prints only those elements of the 2 min read PHP | DsVector merge() Function The Ds\Vector::merge() function is an inbuilt function in PHP which is used to merge all the elements to the vector. Syntax: Ds\Vector public Ds\Vector::merge( $values ) Parameters: This function accepts a single parameter $values which is the traversable object or array.Return Value: This function 2 min read PHP array_diff_key() Function This inbuilt function of PHP is used to get the difference between one or more arrays. This function compares the keys between one or more arrays and returns the difference between them. So, the function generally compares two arrays according to their keys and returns the elements that are present 2 min read Like