例えば生徒の平均点を求めるときに使える
$users = [
["name" => "Taro", "score" => 80, "height" => 165]
["name" => "Taro", "score" => 60, "height" => 160]
["name" => "Taro", "score" => 40, "height" => 155]
["name" => "Taro", "score" => 75, "height" => 150]
["name" => "Taro", "score" => 95, "height" => 145]
];
$avg_score = collection($users)->sumOf('score') / count($users); //70
でもまあ合計を求める関数があるなら平均を求める関数もあるわけで
$avg_height = collection($users)->avg('height'); //150
結論としてCakePHPのコレクションはデータ操作するための関数が揃っていてとても便利
コレクションのメソッド一覧


