Tuesday, 28 August 2018

How to combine two associative arrays in php


I have two associate arrays. I want to combine both. I want to group them to make only one .


Array
(
    [0] => Array
        (
            [min] => 6
            [price] => 100.000
            [sale_price] => 99.000
        )

    [1] => Array
        (
            [min] => 10
            [price] => 100.000
            [sale_price] => 95.000
        )

    [2] => Array
        (
            [min] => 20
            [price] => 100.000
            [sale_price] => 80.000
        )

)

Array
(
    [0] => Array
        (
            [min] => 10
            [your_price] => 94.000
        )

    [1] => Array
        (
            [min] => 15
            [your_price] => 92.000
        )
   [2] => Array
        (
            [min] => 25
            [your_price] => 75.000
        )
)

Now my output should be :
Array
(
    [0] => Array
        (
            [min] => 6
            [price] => 100.000
            [sale_price] => 99.000
            [your_price] => NA
        )

    [1] => Array
        (
            [min] => 10
            [price] => 100.000
            [sale_price] => 95.000
            [your_price] => 94.000

        )
    [2] => Array
        (
            [min] => 15
            [price] => NA
            [sale_price] => NA
            [your_price] => 92.000

        )

    [3] => Array
        (
            [min] => 20
            [price] => 100.000
            [sale_price] => 80.000
            [your_price] => NA
        )

   [4] => Array
        (
            [min] => 25
            [price] => NA
            [sale_price] => NA
            [your_price] => 75.000
        )
)

Is there any function in php that can do this work ?
Keep searching on my own .
Help will be appreciated.
Thank you .

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

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

0 comments:

Post a Comment