I will do that, thank you.
Just one last thing, I'm back to the original code and moved return False; outside the loop. So should this give me some output on the browser? Because I am not getting any. (I commented the whole 2nd question)
<h1>Class number 3 </h1>
<h2>Arrays</h2>
<h3>1. Determine whether or not your number is contained within an array.</h3>
<?php
function findNumber($arr, $num) {
$size = count($arr);
$i = 0;
while ($i < $size) {
if ($arr[$i] == $num) {
return TRUE;
} else {
i++;
}
}
return FALSE;
}
$arr = array(3, 8, 5, 1, 6, 7);
$num = 6;
if (findNumber($arr, $num)) {
echo "Value $num belongs to the array.<br/>";
} else {
echo "Value $num does not belong to the array.<br/>";
}
?>
/*
<h3>2. Determine the average of an array.</h3>
<?php
function avgArr($arr) {
$size = count($arr);
$sum = 0;
for ($i = 0; $i < $size; $i++) {
$sum = $sum + $arr[$i];
}
return $avg = $sum / $size;
}
$myArray = array(1, 2, 3, 4, 5);
echo "The average of your array is: " . avgArr($myArr);
?>
*/