我在数组中遇到了一些问题。 我有3个数组。我想让1行称为历史,然后根据shipment_id插入该行。如果相同shipment_id,它将分组相同的货件ID。见下面的预期结果。如何将数组存储在数组中php
Array a (
[0] => Array (
[order_id] => 231
[name] => "One Layer Lunch Box
[quantity] => 1
[username] => linkath
[shipment_id] => SI000116)
[1] => Array (
[order_id] => 231
[name] => "Test 03
[quantity] => 1
[username] => happymart
[shipment_id] => SI000117))
Array b (
[0] => Array (
[shipment_id] => SI000116
[date] => 2016-11-09 09:40:26
[status] => Ready to ship
[description] => Your item(s) is being packed and ready for shipment at our vendor's warehouse.)
[1] => Array (
[shipment_id] => SI000116
[date] => 2016-11-09 10:16:04
[status] => Shipped
[description] => Your item(s) is being shipped with . For more details on your shipment, please go to Tracking, enter your tracking number))
Array c (
[0] => Array (
[shipment_id] => SI000117
[date] => 2016-11-09 15:27:45
[status] => Ready to ship
[description] => Your item(s) is being packed and ready for shipment at our vendor's warehouse.))
正如预期的那样阵列
Array a (
[0] => Array (
[order_id] => 231
[name] => "One Layer Lunch Box
[quantity] => 1
[username] => linkath
[shipment_id] => SI000116
[history] => Array b (
[0] => Array (
[shipment_id] => SI000116
[date] => 2016-11-09 09:40:26
[status] => Ready to ship
[description] => Your item(s) is being packed and ready for shipment at our vendor's warehouse.)
[1] => Array (
[shipment_id] => SI000116
[date] => 2016-11-09 10:16:04
[status] => Shipped
[description] => Your item(s) is being shipped with . For more details on your shipment, please go to Tracking, enter your tracking number)))
[1] => Array (
[order_id] => 231
[name] => "Test 03
[quantity] => 1
[username] => happymart
[shipment_id] => SI000117
[history] => Array c (
[0] => Array (
[shipment_id] => SI000117
[date] => 2016-11-09 15:27:45
[status] => Ready to ship
[description] => Your item(s) is being packed and ready for shipment at our vendor's warehouse.))
)
)
希望明白我的意思。提前致谢。
这个代码,即时通讯已经尝试过。但不工作。
//tracker
$getshipment = $this->model_account_order->getshipmentByOrder($this->request->get['order_id']);
foreach ($getshipment as $shipment) {
$data['shipment'][] = array(
'shipment_id' => $shipment['shipment_id']
);
}
$i=0;
foreach ($data['shipment'] as $key) {
$gethistorybysid[$i] = $this->model_account_order->getHistory($data['shipment'][$i]['shipment_id']);
$i++;
}
$u=0;
foreach ($getshipment as $final) {
$data['final'][] = array(
'name' => $shipment['name'],
'quantity' => $shipment['quantity'],
'shipment_id' => $shipment['shipment_id'],
'history' => array($gethistorybysid[$u])
);
$u++;
}
print_r($data['final']);
此代码我不知道如何比较相同的装运ID。它有任何方法吗?
无法帮助您输出!应该发布你的尝试代码... –
@ jitendrapurohit..im粘贴我试过的代码。 – ZackZeidy
@ DavidJorHpan.Pasted它.. – ZackZeidy