<?php
print_r(average([4, 1, 5, 3, 7]));
function average($array){
$count = 0;
$sum = 0;
foreach ($array as $item) {
// Calculates the number of array members
$count++;
// Calculates sum of the array
$sum += $item;
}
return $sum/$count;
}
// Using built-in functions
function calculateDetails_builtin($array){
return array_sum($array)/count($array);
}