0
Array
(
    [0] => Array
        (
            [param1] => A0145
            [param2] => Sant Cugat Monastery and Wine Cellar
        )

    [1] => Array
        (
            [param1] => A0150
            [param2] => Collserola La Rierada to Escaletes and El Papiol
        )
)


Array
(
    [0] => Array
        (
            [param1] => Location
            [param2] => Tibidabo
        )

    [1] => Array
        (
            [param1] => Location
            [param2] => Parc Collserola
        )
)

I have the two arrays above. I would like to merge them like shown below: I have tried array_push and array_merge without success. Note that the arrays will vary in lenght. Some might have 0 keys others may have 3, 4 5 etc. Note that in the real world example, each sub-array has 8 named keys, i.e. param1, param2, param3 etc. This is a fixed amount.

with array_push and array_merge it is creating the firs array with a key of 0 and the second array with a key of 1. What I want is one array only with all the sub array contents having sequential key numbers. Like append contents of array 1 into array 0 and re-index the numerical keys.

Does this make any sense? It has been baffling me for some while now.

Array
(
    [0] => Array
        (
            [param1] => A0145
            [param2] => Sant Cugat Monastery and Wine Cellar
        )

    [1] => Array
        (
            [param1] => A0150
            [param2] => Collserola La Rierada to Escaletes and El Papiol
        )

    [2] => Array
        (
            [param1] => Location
            [param2] => Tibidabo
        )

    [3] => Array
        (
            [param1] => Location
            [param2] => Parc Collserola
        )
)
  • "I have tried `array_push` and `array_merge` without success." -- could you share these attempts, please? Thanks. – ggorlen Aug 10 '21 at 22:32
  • 1
    `array_merge` should do it. `array_merge($array1, $array2)` – Barmar Aug 10 '21 at 22:35
  • Thanks Barmar. yes array merge does work exactly as advertised. It does however have a limitation - it can only merge 2 arrays at once! The error came from me being too greedy and trying to merge 3 arrays in one line of code. Issue solved by merging array 0 and array 1. then with another line of code merging (array 0 + array 1) with array 2. – Elliott Farmer Aug 10 '21 at 22:51

0 Answers0