数组合并或合并问题

时间:2015-05-29 06:25:06

标签: php arrays

我有两个数组 Array1 Array2 ,现在我想要结合或者你可以说根据product_option_id在每个数组中将这些数组合并为一个如果product_option_id相同,则将第二个数组数据推入一个。

我的第一个数组是:

Array
(
    [0] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 21
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 1

                )


        )

    [1] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 22
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 2

                )

        )

    [2] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 23
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 3

                )

        )

    [3] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 24
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 4

                )

        )

    [4] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 25
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 5

                )

        )

)

和第二个数组是

Array
(
    [0] => Array
        (
            [DriverInventory] => Array
                (
                    [id] => 21
                    [driver_id] => 10
                    [dispensary_inventory_id] => 12
                    [product_id] => 7
                    [product_option_id] => 2

                )
            [Mydata] => Array
            (
                [price]= 2545
            )    

        )

    [1] => Array
        (
            [DriverInventory] => Array
                (
                    [id] => 22
                    [driver_id] => 10
                    [dispensary_inventory_id] => 13
                    [product_id] => 7
                    [product_option_id] => 3
                    [quantity] => 16

                )
             [Mydata] => Array
                (
                    [price]= 15987
                )    


        )

    [2] => Array
        (
            [DriverInventory] => Array
                (
                    [id] => 23
                    [driver_id] => 10
                    [dispensary_inventory_id] => 14
                    [product_id] => 7
                    [product_option_id] => 4
                    [quantity] => 20

                )

             [Mydata] => Array
                (
                    [price]= 96744
                )    



        )

    [3] => Array
        (
            [DriverInventory] => Array
                (
                    [id] => 24
                    [driver_id] => 10
                    [dispensary_inventory_id] => 15
                    [product_id] => 7
                    [product_option_id] => 5
                    [quantity] => 45

                )
            [Mydata] => Array
                (
                    [price]= 97455
                )    


        )

)

最后我希望成为

的结果
Array
(
    [0] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 21
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 1

                )



        )

    [1] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 22
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 2

                )
            [Mydata] => Array
            (
                [price]= 2545
            )       

        )

    [2] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 23
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 3

                )
            [Mydata] => Array
                (
                    [price]= 15987
                )       

        )

    [3] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 24
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 4

                )
            [Mydata] => Array
                (
                    [price]= 96744
                )      

        )

    [4] => Array
        (
            [DispensaryInventory] => Array
                (
                    [id] => 25
                    [dispensary_id] => 18
                    [product_id] => 7
                    [product_option_id] => 5

                )
             [Mydata] => Array
                (
                    [price]= 97455
                )       

        )

)

1 个答案:

答案 0 :(得分:1)

试试这个。

()