- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
array_merge() function in PHP
The array_merge() function merges one or more arrays into one array. It returns an array in which the elements of all arrays passed in parameters are merged.
Note − In case of same keys of two or more array elements, the last one overrides the other.
Syntax
array_merge(arr1, arr2, arr3, …)
Parameters
arr1 − Initial array to merge
arr2 − Another array
arr3 − Another array
Return
The array_merge() function returns an array in which the elements of all arrays passed in parameters are merged.
The following is an example that merges two array with a key repeated in the second array. In this case the last one overrides the other.
Example
<?php $arr1 = array("p"=>"red","q"=>"green"); $arr2 = array("p"=>"blue","r"=>"yellow"); print_r(array_merge($arr1,$arr2)); ?>
Output
Array ( [p] => blue [q] => green [r] => yellow )
Advertisements