# Combine multiple arrays with array merge

**URL:** <https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102>\
**Category:** General\
**Created:** [April 29, 2024, 9:46am UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102 "2024-04-29T09:46:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rickvzanden](https://forum.alumio.com/user_avatar/forum.alumio.com/rickvzanden/32/247_2.png) [@Rickvzanden](https://forum.alumio.com/u/Rickvzanden)\
**Post date:** [April 29, 2024, 9:46am UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102/1 "2024-04-29T09:46:51Z")

</div>

Hi everyone,

I am looking for a way to merge multiple arrays into one.

I can use the array merge operation to combine one set of arrays, like this below:  
[Mapper: Array Merge / Array Push - iPaaS Transformers / Mappers - Alumio](https://forum.alumio.com/t/mapper-array-merge-array-push/557)

But how would I achieve this is there is not a predefine amount of arrays?  
I will be using the merged storage subscriber and I will end up with 3 or more storage objects that will be added to that.

How can I merge all arrays into one array without knowing how many arrays I got?

PHP Example:

```auto
$data = [
   0 => ["data", "more data"],
   1 => ["data", "more data"],
   2 => ["data", "more data"],
   // ETC
]

$merged_array = [];
foreach($data as $array){
  array_merge($merged_array, $array);
}

```

---

<div class="post-metadata">

**Author:** ![catalin](https://forum.alumio.com/user_avatar/forum.alumio.com/catalin/32/1428_2.png) [@catalin](https://forum.alumio.com/u/catalin)\
**Post date:** [April 29, 2024, 11:48am UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102/2 "2024-04-29T11:48:35Z")

</div>

Hi @Rickvzanden  
Is this the example you are looking for?

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/d/d336f80669b9e17bb1f6accb084691e836c75943.png)

---

<div class="post-metadata">

**Author:** ![Rickvzanden](https://forum.alumio.com/user_avatar/forum.alumio.com/rickvzanden/32/247_2.png) [@Rickvzanden](https://forum.alumio.com/u/Rickvzanden)\
**Post date:** [April 29, 2024, 11:53am UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102/3 "2024-04-29T11:53:08Z")

</div>

I found a way, but its still a bit wonky I believe:

This combines the data I needed and flattens them into a single array:

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/d/ddbe2b94df5816cf0ade81fe5fc6179dd84d4c7e.png)

For example, my data in the the tester containers two arrays with each two records:

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/c/c182285eaa3c25f2e324ca82510ab4667dd6a5ba.png)

This results into a flattened array where the first key is the array key.  
So we remove this one and we are left the pairs containing the data.

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/b/be13592868dd55dfa7ae6c77ee9735355cedb646.png)

But I think there are maybe better ways to do this? It feels so redundant flattening the array and removing the first key.

---

<div class="post-metadata">

**Author:** ![Rickvzanden](https://forum.alumio.com/user_avatar/forum.alumio.com/rickvzanden/32/247_2.png) [@Rickvzanden](https://forum.alumio.com/u/Rickvzanden)\
**Post date:** [April 29, 2024, 11:56am UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102/4 "2024-04-29T11:56:17Z")

</div>

Ah yes, the list get values was the missing piece, that is what I searched for.

Thanks @catalin !

---

<div class="post-metadata">

**Author:** ![mko](https://forum.alumio.com/user_avatar/forum.alumio.com/mko/32/1735_2.png) [@mko](https://forum.alumio.com/u/mko)\
**Post date:** [April 29, 2024, 12:02pm UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102/5 "2024-04-29T12:02:36Z")

</div>

Hi Rick.

I also found a fix using JMESPath, it is very simple.  
Now you can choose between 2 solutions 😉

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/f/f2116af85b9e6a71da21bfedebe5e4feab4b4775.png)

---

<div class="post-metadata">

**Author:** ![Rickvzanden](https://forum.alumio.com/user_avatar/forum.alumio.com/rickvzanden/32/247_2.png) [@Rickvzanden](https://forum.alumio.com/u/Rickvzanden)\
**Post date:** [April 29, 2024, 12:05pm UTC](https://forum.alumio.com/t/combine-multiple-arrays-with-array-merge/1102/6 "2024-04-29T12:05:13Z")

</div>

@mko  
Thank you for giving another way to solve this!
