News新闻

业界新闻动态、技术前沿
Who are we?

您的位置:首页      乐道系统FAQ      PHP 根据key 给二维数组分组

PHP 根据key 给二维数组分组

发布日期:2016-12-09 00:00:00 125

我们经常拿到一个二维数组出来,会发现结果和自己想要的有些偏差,可能需要根据二维数组里的某个字段对数组分组。

先来看以下数组,

Array
(
[0] => Array
(
[id] => 1
[wo_id] => 2
[evaluate_id] => 1
[type] => 分组1
[ctime] => 2016-12-02 11:39:34
)
[1] => Array
(
[id] => 2
[wo_id] => 31
[evaluate_id] => 2
[type] => 分组1
[ctime] => 2016-12-12 11:39:50
)
[2] => Array
(
[id] => 3
[wo_id] => 31
[evaluate_id] => 4
[type] => 分组2
[ctime] => 2016-12-02 11:40:01
)
[3] => Array
(
[id] => 4
[wo_id] => 2
[evaluate_id] => 5
[type] => 分组2
[ctime] => 2016-12-07 10:21:40
)
[4] => Array
(
[id] => 5
[wo_id] => 2
[evaluate_id] => 3
[type] => 分组2
[ctime] => 2016-12-07 10:21:51
)
[5] => Array
(
[id] => 6
[wo_id] => 2
[evaluate_id] => 2
[type] => 分组3
[ctime] => 2016-12-07 10:21:56
)
[6] => Array
(
[id] => 7
[wo_id] => 4
[evaluate_id] => 2
[type] => 分组3
[ctime] => 2016-12-07 10:22:10
)
)