Laravel

Laravel Collection Public API: average

Author

John Koster

Published on November 30, 2016

average($key = null)

The average method is simply an alias of the avg (discussed in the Laravel Collection Public API: avg article) method, and can be used in exactly the same way to calculate the averages of items within a collection.

1<?php
2 
3// Results in 12.5
4collect([5, 10, 15, 20])->avg();
5 
6// Results in 12.5
7collect([5, 10, 15, 20])->average();