我有一个像mysql join那样获取的结果:
job_card_id
我想基于registration_no
和Array(
[0]=>Array
(
[job_card_id] => 1
[registration_no] => DL 17U 7113
[repair_order]=>Array
(
[0]=>Array
(
[repair_order_id] => 1
[customer_request] => test customer request
[qty] => 5
)
[1]=>Array
(
[repair_order_id] => 2
[customer_request] => test customer request1
[qty] => 5
)
)
)
[1]=>Array
(
[job_card_id] => 2
[registration_no] => DL 17U 6111
[repair_order]=>Array
(
[0]=>Array
(
[repair_order_id] => 4
[customer_request] => test customer request
[qty] => 5
)
[1]=>Array
(
[repair_order_id] => 5
[customer_request] => test customer request1
[qty] => 5
)
)
)
)
将其分组,例如:
WeatherData.toString()
我如何产生这种结果,请帮忙,谢谢。
答案 0 :(得分:0)
您可以对数组使用bu迭代并创建新数组:
$newArr = [];
foreach($arr as $value)
{
$key = $value['job_card_id'].$value['registration_no'];
if (!isset($newArr[$key]))
{
$newArr[$key] = [
'job_card_id' => $value['job_card_id'],
'registration_no' => $value['registration_no'],
'repair_order' => [],
];
}
$newArr[$key]['repair_order'][] = [
'repair_order_id' => $value['repair_order_id'],
'customer_request'=> $value['customer_request'],
'qty' => $value['qty'],
];
}
$newArr = array_values($newArr);
$arr
是您的数组