Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Merge two arrays keeping original keys in PHP
To merge two arrays keeping original keys in PHP, the code is as follows−
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 another example −
<?php
$arr1 = array();
$arr2 = array("a" => "Jacob");
var_dump ($arr1 + $arr2);
?>
Output
This will produce the following output−
array(1) {
["a"]=>
string(5) "Jacob"
}Advertisements