如何更改此多数组的结构

时间:2018-12-06 18:12:52

标签: php arrays

我有两个数组,我尝试将它们推到一个数组中,但没有像这样的键0:

 $array[] = $cart_info;
 $array[] = $new_cart_items;
Array
(
    [0] => Array
        (
            [A3ePDKuBTLF7hGOXJfWSI2os8RlYZQ69] => Array
                (
                    [id] => 189
                    [qty] => 1
                    [price] => 10.00
                    [name] => 1
                    [rowid] => A3ePDKuBTLF7hGOXJfWSI2os8RlYZQ69
                    [subtotal] => 10.00
                    [options] => Array
                        (
                            [unit_id] => 1
                            [Offer] => 0.00
                        )

                )

        )

    [1] => Array
        (
            [cXtxv82G0ROLrB64Vf3ZM7mNDdezTK5F] => Array
                (
                    [id] => 188
                    [qty] => 1
                    [price] => 10.00
                    [name] => 1
                    [options] => Array
                        (
                            [Offer] => 5.00
                            [unit_id] => 1
                        )

                    [rowid] => cXtxv82G0ROLrB64Vf3ZM7mNDdezTK5F
                    [subtotal] => 20
                )

        )

)

**并且我想更改此结构以替换作为此哈希的键,我也不知道哈希,因为它是动态的**

Array
(
    [aa7a2aa7357d176f175b5ac44397745b] => Array
        (
            [id] => 189
            [qty] => 1
            [price] => 10
            [name] => sfsfsf
            [options] => Array
                (
                    [Offer] => 0.00
                    [unit_id] => 1
                )

            [rowid] => aa7a2aa7357d176f175b5ac44397745b
            [subtotal] => 10
        )

    [c2832106fdb6a068de0a293fabdebc75] => Array
        (
            [id] => 188
            [qty] => 1
            [price] => 10
            [name] => Coffee of Excellence
            [options] => Array
                (
                    [Offer] => 5.00
                    [unit_id] => 1
                )

            [rowid] => c2832106fdb6a068de0a293fabdebc75
            [subtotal] => 10
        )

)

1 个答案:

答案 0 :(得分:0)

尝试一下:

 $array = array_merge($cart_info, $new_cart_items);

另请参阅http://php.net/manual/ru/function.array-merge.php