嗨,我正在使用 laravel,我有一个数组 这个数组有一些键,其中一些是字符串,我想将它们更改为 int,并且所有键都将是 int
$nativeContent = NativeContent::find($id);
$nativeContentView = $nativeContent->countViewNative()
->orderBy('created_at', 'ASC')
->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('m'); // grouping by months
});
试试这个:
->groupBy(function($date) {
return intval(Carbon::parse($date->created_at)->format('m')); // grouping by months
});
如果您有收藏,可以轻松实现,方法是:
$newListWithIntKeys = $nativeContentView->values();
这将使用从 0 到 N 开始的常规连续整数,而不是您的命名键。
已在 Laravel 10 中验证