Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP Array Functions
Next article icon

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


Next Article
PHP Array Functions

V

vkash8574
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.
    8 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 array_multisort() Function
    The array_multisort() is an inbuilt function in PHP which is used to sort multiple arrays at once or a multi-dimensional array with each individual dimension. With this function, one should remember that string keys will be maintained, but numeric keys will be re-indexed, starting at 0 and increases
    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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences