Laravel - Collections - Method Avg

The avg method returns the average value of a given key:

    
    $average = collect([
        ['foo' => 10],
        ['foo' => 10],
        ['foo' => 20],
        ['foo' => 40]
    ])->avg('foo');
    
    // 20
    
    $average = collect([1, 1, 2, 4])->avg();
    
    // 2