我正在开发我们的订单系统以显示每个部门需要完成的特定订单。我在多维数组中拥有所有必要的数据。但我想合并任何具有相似值的数组。
Array
(
[0] => Array
(
[id] => 16111
[order_id] => 1234
[item_id] => Product 1
[invoice_id] => 98765
[acc_id] => 1
[name] => John Smith
[phone] => 000000000
)
[1] => Array
(
[id] => 16112
[order_id] => 1234
[item_id] => Product 2
[invoice_id] => 98765
[acc_id] => 1
[name] => John Smith
[phone] => 000000000
)
[2] => Array
(
[id] => 16113
[order_id] => 1235
[item_id] => Product 3
[invoice_id] => 98721
[acc_id] => 11
[name] => Bob Jones
[phone] => 222222222
)
[3] => Array
(
[id] => 16114
[order_id] => 1236
[item_id] => Product 4
[invoice_id] => 98754
[acc_id] => 3
[name] => Fred Bill
[phone] => 111111111
)
[4] => Array
(
[id] => 16115
[order_id] => 1236
[item_id] => Product 1
[invoice_id] => 98754
[acc_id] => 3
[name] => Fred Bill
[phone] => 111111111
)
)
我们可以看到我们有 5 个产品要发送给客户。但是 John Smith 和 Fred Bill 都想要多个项目。与其将数据存储在每个项目的数组中,不如将其设为每个客户的数组。基于订单编号。所以我希望数组最终看起来像这样。
Array
(
[0] => Array
(
[0] => Array
(
[id] => 16111
[order_id] => 1234
[item_id] => Product 1
[invoice_id] => 98765
[acc_id] => 1
[name] => John Smith
[phone] => 000000000
)
[1] => Array
(
[id] => 16112
[order_id] => 1234
[item_id] => Product 2
[invoice_id] => 98765
[acc_id] => 1
[name] => John Smith
[phone] => 000000000
)
)
[1] => Array
(
[id] => 16113
[order_id] => 1235
[item_id] => Product 3
[invoice_id] => 98721
[acc_id] => 11
[name] => Bob Jones
[phone] => 222222222
)
[2] => Array
(
[0] => Array
(
[id] => 16114
[order_id] => 1236
[item_id] => Product 4
[invoice_id] => 98754
[acc_id] => 3
[name] => Fred Bill
[phone] => 111111111
)
[1] => Array
(
[id] => 16115
[order_id] => 1236
[item_id] => Product 1
[invoice_id] => 98754
[acc_id] => 3
[name] => Fred Bill
[phone] => 111111111
)
)
)
产品 1 也是邮政和包装,因此我想将数据回显到表格中。但我不希望 Post 和 Packaging 拥有它自己的行,而是在该数组中的其他产品的行中确定一个字段。所以在一个表格中,我们会看到例如:
- John Smith Product2 Courier(由 product1 的存在确定) 000000000
如果客户有多种产品,这需要工作,即
- John Smith Product3 Courier(由 product1 的存在确定) 000000000
- John Smith Product4 Courier(由 product1 的存在确定) 000000000
- John Smith Product5 Courier(由 product1 的存在确定) 000000000