[英]Laravel map to group collection
I do laravel map to group and got this我做 laravel map 分组并得到了这个
I want it become like this我希望它变成这样
"Ilmu Pengetahuan Alam" => array:6 [▶
[
"2022-08-01" => "Hadir"
]
[
"2022-08-03" => "Sakit"
]
[
"2022-08-05" => "Hadir"
]
[
"2022-08-06" => "Hadir"
]
[
"2022-08-08" => "Hadir"
]
[
"2022-08-13" => "Hadir"
]
]
"Pendidikan Pancasila dan Kewarganegaraan" => array:1 [
[
"2022-08-13" => "Hadir"
]
]
is it possible?可能吗? and add dates of this month to the array which is not on there
并将本月的日期添加到不存在的数组中
read in laravel document with https://laravel.com/docs/9.x/collections#method-groupby使用https://laravel.com/docs/9.x/collections#method-groupby读取 laravel 文档
Example
例子
$collection = collect([
['account_id' => 'account-x10', 'product' => 'Chair'],
['account_id' => 'account-x10', 'product' => 'Bookcase'],
['account_id' => 'account-x11', 'product' => 'Desk'],
]);
$grouped = $collection->groupBy('account_id');
$grouped->all();
/*
[
'account-x10' => [
['account_id' => 'account-x10', 'product' => 'Chair'],
['account_id' => 'account-x10', 'product' => 'Bookcase'],
],
'account-x11' => [
['account_id' => 'account-x11', 'product' => 'Desk'],
],
]
*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.