【问题标题】:how to change the structure for this multi array如何更改此多数组的结构
【发布时间】:2019-05-08 12:04:47
【问题描述】:

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

 $array[] = $cart_info;
 $array[] = $new_cart_items;
数组
(
    [0] => 数组
        (
            [A3ePDKuBTLF7hGOXJfWSI2os8RlYZQ69] => 数组
                (
                    [id] => 189
                    [数量] => 1
                    [价格] => 10.00
                    [名称] => 1
                    [rowid] => A3ePDKuBTLF7hGOXJfWSI2os8RlYZQ69
                    [小计] => 10.00
                    [选项] => 数组
                        (
                            [unit_id] => 1
                            [报价] => 0.00
                        )

                )

        )

    [1] => 数组
        (
            [cXtxv82G0ROLrB64Vf3ZM7mNDdezTK5F] => 数组
                (
                    [id] => 188
                    [数量] => 1
                    [价格] => 10.00
                    [名称] => 1
                    [选项] => 数组
                        (
                            [报价] => 5.00
                            [unit_id] => 1
                        )

                    [rowid] => cXtxv82G0ROLrB64Vf3ZM7mNDdezTK5F
                    [小计] => 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
        )

)

【问题讨论】:

  • 你的 PHP 代码在哪里?
  • $array[] = $cart_info; $array[] = $new_cart_items;

标签: php arrays


【解决方案1】:

试试这个:

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

另见http://php.net/manual/ru/function.array-merge.php

【讨论】:

    猜你喜欢
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2021-12-27
    • 2021-08-28
    • 2020-10-23
    相关资源
    最近更新 更多