<?php $score= array (66,75,78,55,54); . averager($scores); . ?>
<html>
<head>
<title>Passing Array to Functions </title>
<body>
<h1>Passing Array to Functions </h1>
<?php
$scores=array(66,75,78,55,54);
averager($scores);
function averager($array)
{
$total=0;
foreach ($array as $value)
{
$total += $value;
}
if(count($array)>0)
{
echo "The average was", $total/count($array);
}
else
{
echo "No element to average!";
}
}
?>
</body>
</html>
Output:
Others
Languages
Frameworks
Web / Design
Mobile Technology
Sql & Technology
R4R