Questions tagged [array-merge]

Array-merge means elements of one or more arrays will be merged together into a single array.

Array-merge means merging the elements of one or more arrays together into a single array so that the values of one are appended to the end of the previous one.

array array_merge ( array $array1 [, array $... ] )

Example

$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);

Result

Array
(
    [color] => green
    [0] => 2
    [1] => 4
    [2] => a
    [3] => b
    [shape] => trapezoid
    [4] => 4
)

Reference

819 questions
-2
votes
4 answers

PHP Merge (Add) Two Arrays by Same Key

I have two arrays. $a = array('a' => 2, 'b' => 5, 'c' => 8); $b = array('a' => 3, 'b' => 7, 'c' => 10); I want to merge these two arrays and get following result. $c = array('a' => 5, 'b' => 12, 'c' => 18); What is the easiest way to archive…
Vajira Lasantha
  • 2,435
  • 3
  • 23
  • 39
-2
votes
2 answers

I want to join 2 arrays with a standard usable

I have array1 array1( 'orange' => 'orange' 'banana' => 'banana' ); and array2 array2( 0 => 'apple' 1 => 'watermellon' 2 => 'orange' 3 => 'potatoes' 4 => 'lemon' 5 => 'banana' ) and i want to take as reply array3( 2…
Karmen
  • 238
  • 2
  • 15
-2
votes
1 answer

Combining two arrays with unique field

Combining A array and B array and want the result show below EDITED a = { [0]=> array(2) { ["pid"]=> string(1) "1" ["val1"]=> string(1) "1" } [1]=> array(2) { ["pid"]=> string(2) "12" …
balaji
  • 291
  • 1
  • 4
  • 13
-2
votes
2 answers

PHP array_merge: argument not an array?

I'm getting some weird behaviour in PHP that I just can't understand. $count=0; $temp=array(); //this is definitely a new variable, not that it should matter foreach($array as $arr) { if ($arr->bbcode != $previous_bb) { …
ShakesBeer
  • 283
  • 4
  • 15
-2
votes
1 answer

Merge/Combine Keys of an array

I have the following result from authenticating a Facebook profile: Array ( [provider] => Facebook [uid] => value [info] => Array ( [name] => value [image] => value [nickname] => value …
Chris Burton
  • 1,195
  • 6
  • 19
  • 54
-2
votes
3 answers

PHP: Issue combining sub-arrays into new array

Working on a poll script, but I have little problems with the options of a poll, creating a new array of it. The actual example array contains 3 sub-arrays with options, sum of votes and percentage: Array ( [poll_options] =>…
lickmycode
  • 2,069
  • 2
  • 19
  • 20
-2
votes
2 answers

How to merge two arrays from SQL query?

I've got following two queries : SELECT date( FROM_UNIXTIME( user_reg_date ) ) 'Current Date', COUNT( * ) 'registered_user' FROM users WHERE user_reg_date >=1341100800 AND user_reg_date <=1374451200 GROUP BY date( FROM_UNIXTIME( user_reg_date )…
PHPLover
  • 1
  • 51
  • 158
  • 311
-2
votes
1 answer

Second value being passed in function - What is it?

I've tried looking through other places but I can't seem to find the answer. I know that a function can have more than one value being passed into it because the function itself accommodates for the two values. In this function right below, I can…
moto
  • 194
  • 3
  • 13
-2
votes
5 answers

php - Adding an element form one array into another

I have 2 arrays like so: $array1 = array( array("foo"=>"bar","count"=>"3"), array("foo2"=>"bar2","count"=>"4"), array("foo3"=>"bar3","count"=>"2") ); $array2 = array( array("foo4"=>"bar","count"=>"3"), …
Krimson
  • 7,386
  • 11
  • 60
  • 97
-2
votes
1 answer

How to Create a Key and Bind the Array Values in Multidimensional Way PHP

I have data here: Here's the result of my first function.The variable I used for the result was $this->arrays. Array ( [1] => Array //Transactiondetails of SiteID 1 ( [SiteID] => 1 [Balance] => 2000 [MinBalance] => 1000 …
Mic
  • 81
  • 2
  • 12
-3
votes
1 answer

Check if an array is a merge of 2 arrays

Implement a function checking if a given array can be constructed as a merge of the 2 other arrays in any way. public static boolean isMerge(int[] arr1, int[] arr2, int[] merge){ //... } Examples: isMerge([3, 1, 2, 2], [2, 1, 1], [3, 1, 2, 2, 2,…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
-3
votes
1 answer

Merge arrays in multidimensional array based on multiple values

[ 0 => [ 'qty' => 10 'section' => 'VK7B' 'time_window' => 1 ] 1 => [ 'qty' => 1 'section' => 'STIC' 'time_window' => 1 ] 2 => [ 'qty' => 1 'section' => 'STIC' …
Bowis
  • 541
  • 8
  • 31
-3
votes
1 answer

How to merge arrays vertically in PHP?

Assume I have multiple nested arrays (arrays of rows-arrays): [ ['name' => 'John', 'age' => 20], ['name' => 'Jack', 'age' => 30], ], [ ['salary' => 100], ['salary' => 200], ], How do I merge the columns? Like this: [ ['name' =>…
whyer
  • 783
  • 5
  • 16
-3
votes
2 answers

Combine 2 Array into a new string

I have 2 Javascripts Array var array1 = ["Mergen Morry","Dash Borad","Mergen Xss"]; var array2 = ["02111356","4458763","02111356"]; I want the output to be like this Mergen Morry – 02111356 : data uploaded Dash Borad - 4458763 : data…
drfrost
  • 5
  • 1
  • 2
-3
votes
1 answer

Merging two arrays by index or combine array?

I have two simple arrays structured like the (simplified) example below. I simply want to merge them into one array. $array1 : Array ( [0] => Array ( [user_id] => 65 [paid] => 24809 ) [1] => Array ( [user_id] => 54 [paid]…
Jay
  • 151
  • 1
  • 13
1 2 3
54
55