Function in PHP
<?php
//function in php
function processMarks($marksArr) {
$sum = 0;
foreach($marksArr as $value) {
$sum += $value;
}
return $sum;
}
function avgMarks($marksArr) {
$sum = 0;
$i = 1;
foreach($marksArr as $value) {
$sum += $value;
$i++;
}return $sum/$i;
}
$rohan = [34, 98, 15, 76, 97, 96];
//$sumMarks = processMarks($rohan);
$sumMarks = avgMarks($rohan);
echo "Total marks scored by rohan out of 600 is $sumMarks";
?>
Comments
Post a Comment