Laravel 对集合使用总和,平均,最小值或最大值进行统计计算
示例
集合还为您提供了一种进行简单统计计算的简便方法。
$books = [ ['title' => 'The Pragmatic Programmer', 'price' => 20], ['title' => 'Continuous Delivery', 'price' => 30], ['title' => 'The Clean Coder', 'price' => 10], ] $min = collect($books)->min('price'); //10 $max = collect($books)->max('price'); //30 $avg = collect($books)->avg('price'); //20 $sum = collect($books)->sum('price'); //60