merge array in php

Solutions on MaxInterview for merge array in php by the best coders in the world

showing results for - "merge array in php"
Elya
04 Feb 2020
1
2<?php
3$array1 array("color" => "red"24);
4$array2 array("a""b""color" => "green""shape" => "trapezoid"4);
5$result = array_merge($array1$array2);
6print_r($result);
7?>
8Array
9(
10    [color] => green
11    [0] => 2
12    [1] => 4
13    [2] => a
14    [3] => b
15    [shape] => trapezoid
16    [4] => 4
17)
18
Harley
15 Nov 2019
1<?php
2
3$array1 = array('key1' => 'test1', 'key2' => 'test2');
4$array2 = array('key3' => 'test3', 'key4' => 'test4');
5
6$resultArray = array_merge($array1, $array2);
7
8// If you have numeric or numeric like keys, array_merge will 
9// reset the keys to 0 and start numbering from there
10
11$resultArray = $array1 + $array2;
12
13// Using the addition operator will allow you to preserve your keys,
14// however any duplicate keys will be ignored.
Juan Martín
12 May 2019
1$output = array_merge($array1, $array2);
Tiphaine
19 May 2019
1/* Array merge is basically use to merge the two array data. */
2  
3<?php
4$a1=array("red","green");
5$a2=array("blue","green","yellow");
6print_r(array_merge($a1,$a2));
7?>
8  
9/*
10Output:
11Array ( [0] => red [1] => green [2] => blue [3] => green [4] => yellow )
12*/
13  
14<?php
15$a1=array("a"=>"red","b"=>"green");
16$a2=array("c"=>"blue","b"=>"yellow");
17print_r(array_merge($a1,$a2));
18?>
19
20/*
21Output:
22Array ( [a] => red [b] => yellow [c] => blue )
23*/
24  
25/* In above example you can check the difference in output 
26it takes all values of both array in final output, but not in associative array you can check.
27because one value gets overwritten by same key reference in both array.
28*/
29
Pedro
30 Jul 2016
1$a1=array("red","green");
2$a2=array("blue","green","yellow");
3print_r(array_merge($a1,$a2));
queries leading to this page
merge array inside array phpphp merge two arraysconcat multiple arrays phpmerga two arrays phpphp concat arraytwo array combine phpphp concat associative arrayphp merget 2 arraysphp merge 3 arraysarray merge phphow to combine two associative array in phpphp arrray mergehow to concate two array in phpphp two different array mergelaravel merge arraysphp combine associative arraysphp array merge example 2b laravelmerge two arrays laravelsymfony php merge two arraysphp join arraysphp two array mergemerge associative array in phparray merge foreach phpmerge to array in phpmerge all arrays in array laravelphp merge array columnsmerge two associative array in phpmerge 2 arrays phptwo array join in phpmerge duplicate key value in array phptwo arrays in one variable2 array merge in phpconcat php arrayphp combine multiple arraysphp array in array mergeconcat array phophp merge array associativearray combine in phparray merge phpphp combine arraymerge elements of two array phpphp array concatenationarray merge php laravelphp combine multiple associative arrayphp combine 2 arraysphp join 3 arrays togetherconcat array values phparray merge in laravelphp dearray mergemarge two array in phphow to merge 2 arrays in phpphp merge 2 arraysconcat arrayphphow to merge associative array in phpphp array combinemerge two arrays phpmerge arrays laravelphp array margemerge two arrays in laravelphp merge array valuesphp concatenate arrayarray marge phpconcatenate array phphow we merge two array in phphjoin arrauys phparray mergephp array mergephp add two arrays togetherconcat array phpphp merge two arrayarray combine phpdifference array merge 28 29 and array combine 28 29 in phpphp code to combine two arraysjoin two associative arrays phparray merge phphconcatenate arrays in phpappend two array in phpmerge array phpconcat array in phpphp array merge for associative arrayshow to merge two array data in phpphp concatenar arraysphp combine arrayscombining php arraysarray merge phpmerge and uniquein phpphp array combinejoin 2 dictionaries in phpphp array mergehow to merge to array in phpmerge only different value phparray merg filling phpmerge one array by specific fieldarray merge in phpphp marge 2 arrayslaravel array mergejoin array in phpmerge multi array phpphp concat array to arraycombine 2 array within an array phpmerge two array phpphp merge arraysjoin two arrays phpmerge two php arraysmerge arrays in phpmerge array in phpmerge 2 arrays in phpmerge arrays phpconcatenate arrays phphow to merge array forhow to call merge array in controller codeignitercombine array in phpconcatenate array in phphow to combine two arrays phparray concat phpjoin elements of associative array phpphp array unionphp array concatarray marge in phpphp combine two arraysmarge 2 arrag phpmerge php arraymerge to array phparray merge in phparray merge 28 29cphp combine arraysarray merge 28php join two arraysphp union two arrayshow to merge array phpcombine two arrays phptwo array merge in phpphp join 2 arraysmerge one array into another php larabvelphp combine values of two arraysjoin arrays phpconcat arrays phpphp merge 2 associative arraysmerge arrays inside array phpmerge multiple arrays phphow to union array phpphp arrary mergeconcatonate array phplaravel merge two arraysdata merge array phparray merge associative phpphp merge associative arrays by keyhow to merge 2 arrays phpcombine php arraysconcat two arrays phparray mergein phpphp merge arrayhow to merge array in phpphp join 2 arrayarray merge php associativearray inside array php mergeconcatinate two array php array merge phpjoined 2 array inphpphp concat arraysphp mege array argumentcombine array in same variable in phphow to marge 2 array in phparray merging phparray merge keys and values phpmerge 2 array in phphow merge array in phpphp array merge preserve none empty valueshow to join two arraylist in php how to check the values of array then merge them in phpphp merge multidimensional associative arrayhow to merge two associative array in phphow to combine two arrays in phpmerge arrys phpphp join value from aray and ke fron arrayphp merge one array into anotherphp array merge not workingphp merge associative arraysmerge 2 array phparray merge laravelphp array push vs array mergemerge arraycodeigniter merge multiple arrayjoin two arrays laravelmerge associative array phpmerge array in end of array phpadding 2 arrays in phpmerge 2 arrays in laravelarray merge in php laravelarray merge in pharray php mergearray union phpphp array join two arraysphp array merge associativearray merge phpmerge array values phpmerge 2 associtive array in phpmerge two array in phpmerge array of arrays phpcombine to array phpphp require return array mergehow to merge two list in phpadd two asspciative arrays together phparray merge in php with int keysphp combine two arraymerge more than 2 arrays phparray mergephp how to merge two arraysjoin 2 arrays in phpphp merge 2 arrayconcat variable php array with stringcombine array into associative array phpphp concate arrayscombine two arrays in phpmerge two array using phparray merge in laravelarray concat in phpphp array lost key when concatmerge array in php