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
2 answers

PHP Array of Objects with arrays inside. Merge these

I have an array of Objects. These Objects have different keys with arrays as value. As an output I need a combined array of all these Array. Example: [ { id: 1, datas: [a,b,c] }, { id: 2, datas: [d,e,f] }, { id: 3, …
Introser
  • 161
  • 1
  • 12
-2
votes
1 answer

array_merge does not work for 2 special json arrays

There are 2 json arrays and need to merge them but array_merge does not work I've searched and found out the json arrays where could be merged truly with array_merge Here are my json data available in separate files: { "J": [ { "a":…
AndroidPlayer2
  • 346
  • 1
  • 2
  • 13
-2
votes
1 answer

Split array into equal parts order by id using PHP

I have a Array list as below, how to split them into equal parts, sort equal parts by id, and merge equal parts in a id using PHP? Array ( [0] => Array ( [id] => 121 [owner] => xa [name] => xjs …
Elsa
  • 1
  • 1
  • 8
  • 27
-2
votes
3 answers

Grouping data using a value from a deep subarray

How can I assign first level keys using a column value from the third level of a multidimensional array? My input: $array = [ [ ["ID" => 2, "vendor_id" => "37", "order_id" => 776], ], [ ["ID" => 2, "vendor_id" => "37",…
-2
votes
2 answers

SWIFT 5.1 Merge 2 arrays of different data types?

FOR SWIFT 5.1 How do you get an array of strings to merge with an array of integers? stringArray: ["Tom", "Dick", "Harry"] intArray: [ 1, 2, 3] The result I am looking for is a list where the format would be String:Int Tom: 1 Dick: 2 Harry: 3
-2
votes
4 answers

Multiple array with same key value merge into an array

I'm facing a problem with multiple array calculation. I am using database mysql and operation language is PHP. When I'm fetching an result from database result show multiple array with fixed key and value. When one array key code value is same as…
raihan
  • 2,225
  • 4
  • 14
  • 19
-2
votes
2 answers

how to merge two array objects in javascript

Just wondering what is my best approach to merge these two arrays together. example var a = [{"ID":11021,"ASSET_NAME":"panda","SERVICE_NAME":"Open Ticket"}] var b = [{"ID":11021,"ASSET_NAME":"panda","SERVICE_NAME":"open requests"}] Looking to…
user3292394
  • 609
  • 2
  • 11
  • 24
-2
votes
1 answer

How to merge an associative array with the next iterating var?

The PHP lab at hand Implement a groupByOwners function that: Accepts an associative array containing the file owner name for each file name. Returns an associative array containing an array of file names for each owner name, in any order. For…
c0ldtrain
  • 17
  • 5
-2
votes
1 answer

Array Merge Dynamic Multidimensional Array by Key

This is my multidimensional array example. This is generated through a form so this is a dynamic array, so there may be more than 3 entries. $array = [ [ 'itemNo' => 1, 'desc' => [ ['serialNo' => 1, 'name' => 'a'], …
user2122151
  • 51
  • 2
  • 8
-2
votes
4 answers

Merge two array with index in php

I have code like this foreach($tests as $test){ if($test=='true') { $temp[]['name']='a'; $temp[]['child']='b'; } else{ $temp[]['name']='c'; …
paranoid
  • 6,799
  • 19
  • 49
  • 86
-2
votes
1 answer

How to merge these two objects in Angular JS?

I need help merging two objects in AngularJS :) I'm using the trakt.tv API (http://docs.trakt.apiary.io/) to pull in history data. This returns a list of movies and episodes the user has watched (see:…
webslash
  • 53
  • 1
  • 8
-2
votes
5 answers

Join two associative arrays by their keys, then produce another associative array

$arr = array( array("one" => 1, "two-two" => 2, "four" => 4), array("two-two" => 22, "three" => 33, "four" => 44) ); $keys = array_flip( array_keys( call_user_func_array('array_merge', $arr) ) ); array_walk( $keys, …
Tom Auger
  • 19,421
  • 22
  • 81
  • 104
-2
votes
1 answer

Assign the values of one array to another not merging

I need to append certain values of Second array to the first array I.e., In the First Array i create two elements such as name and price and get the values from Second Array and give it to first array Here is my First Array [ { "id": 8, …
SA__
  • 437
  • 3
  • 7
  • 13
-2
votes
1 answer

Scan folders and load files from folder

I have a folder structure: - components --com_name ---routes ----routes.json --com_another_name ---routes ----routes.json ... --com_x ---routes ----routes.json How can I load every routes.json file from each com_x folder and merge to one…
XTRUST.ORG
  • 3,280
  • 4
  • 34
  • 60
-2
votes
1 answer

PHP - Map two Arrays based on Key

User Array print_R($user_array); Array ( [0] => Array ( [SKILL_NAME] => Application Software [EXPERIENCE_BAND] => 15+ [SITE_STATUS] => Onsite [NO_OF_RESOURCE] => 1 …
Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121