

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between array_merge and array + array in PHP?
Both get the union of arrays, but array_merge() overwrites duplicate non_numeric keys. Let us now see an example of the array+array−
Example
<?php $arr1 = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110"); $arr2 = array("t"=>"115", "u"=>"103", "v"=>"105", "w"=>"125" ); var_dump ($arr1 + $arr2); ?>
Output
This will produce the following output−
array(8) { ["p"]=> string(3) "150" ["q"]=> string(3) "100" ["r"]=> string(3) "120" ["s"]=> string(3) "110" ["t"]=> string(3) "115" ["u"]=> string(3) "103" ["v"]=> string(3) "105" ["w"]=> string(3) "125" }
Example
Let us now see an example of array_merge() in PHP−
<?php $arr1 = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110"); $arr2 = array("t"=>"115", "u"=>"110", "v"=>"105", "w"=>"100" ); var_dump (array_merge($arr1, $arr2)); ?>
Output
This will produce the following output−
array(8) { ["p"]=> string(3) "150" ["q"]=> string(3) "100" ["r"]=> string(3) "120" ["s"]=> string(3) "110" ["t"]=> string(3) "115" ["u"]=> string(3) "110" ["v"]=> string(3) "105" ["w"]=> string(3) "100" }
- Related Questions & Answers
- What is the difference between a python list and an array?
- Difference Between Array and Structure
- Difference Between Array and Pointer
- What is the difference between a list and an array in C#?
- Difference Between Array and Linked List
- Difference Between Character Array and String
- Difference between pointer and array in C
- Difference between Array and Pointers in C.
- Difference between Structure and Array in C
- Difference between first and the second array in JavaScript
- What is the difference between the size of ArrayList and length of Array in Java?
- Merge and remove duplicates in JavaScript Array
- Difference between String and Character array in Java.
- Difference between List and Array types in Kotlin
- Merge Sorted Array in Python
Advertisements