November 30, 2016 —John Koster
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<?php2 3// Results in 12.54collect([5, 10, 15, 20])->avg();5 6// Results in 12.57collect([5, 10, 15, 20])->average();
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.