我有一个包含一些数据的数组,我想按年份拆分它,得到以年份为值的子数组和以相同年份为键的项数组。Start数组类似于:$arr = [
0 => Array(
'name' => 'Some name',
'description' => 'some description',
'year' => 2019
),
1 => Array(
'name' => 'Some name 1',
'description' => 'some description 1',
'year' => 2020
),
2 => Array(
'name' => 'Some name 2',
'description' => 'some description 2',
'year' => 2020
),
];
我想得到一个数组,按年份拆分,如下所示:$arr = [
'2019' => Array(
0 => Array(
'name' => 'Some name',
'description' => 'some description',
'year' => 2019
),
),
'2020' => Array(
0 => Array(
'name' => 'Some name 1',
'description' => 'some description 1',
'year' => 2020
),
1 => Array(
'name' => 'Some name 2',
'description' => 'some description 2',
'year' => 2020
),
),
];
什么PHP函数能做到这一点?