我有一个相关的结果数组。我需要根据它们的类别对数组进行分组。例如:与类别相关的作业将在单次迭代下合并。
用于制作的代码:
$result = array();
foreach ($group as $element) {
$result[$element['category']][] = $element;
}
[Professional Services / Consulting / Project Mgmt] => Array
(
[0] => Array
(
[category] => Professional Services / Consulting / Project Mgmt
[jobs] => Array
(
[0] => stdClass Object
(
[date] => 12/11/2019
[country] => IND
)
)
)
[1] => Array
(
[category] => Professional Services / Consulting / Project Mgmt
[jobs] => Array
(
[0] => stdClass Object
(
[date] => 02/11/2019
[country] => US
)
[1] => stdClass Object
(
[date] => 03/11/2019
[country] => SS
)
)
)
)
但我需要如下数据:
[Professional Services / Consulting / Project Mgmt] => Array
(
[0] => Array
(
[category] => Professional Services / Consulting / Project Mgmt
[jobs] => Array
(
[0] => stdClass Object
(
[date] => 12/11/2019
[country] => IND
)
)
)
)
请帮我解决一下这个。
小怪兽爱吃肉