Laravel get numeric array average

Laravel

Nicesnippets

358

02-05-2020


Hello Friends,

Using laravel avg() and average() collection method you can get avearage of array. how to find array average in laravel collection. you can Calculating Averages Using Collections in Laravel.

public function index()

{

$average = collect([1, 5, 9, 5])->avg();

// Output : 5

$average = collect([10,20,30])->average();

// Output : 10

}

I hope it can help you...