<?php
//array
$lessFifty = array();
$moreFifty = array();
//number generation
for ($i = 1; i<=30; $i++) {
$number = rand(0, 100);
//Sorting <50>
if ($number < 50 ) {
$lessFifty[] = $number;
} else {
$moreFifty[] = $number;
}
}
print_r($lessFifty);
print_r($moreFifty);
//Average
echo "<p> average of values less than fifty: </p>";
array_sum($lessFifty) / count($lessFifty) ;
echo "<p> average of values greater than fifty: </p>" ;
array_sum($moreFifty) / count($moreFifty) ;
?>
This is what I have so far. I'm trying to generate 50 random numbers within the range of 0-100. Then I have to sort it into less than or greater than 50.
I also have to calculate the average, range, and median.
When I try to do up to the average, and put it into my browser (with a server enabled), I get a blank page. No errors, just a blank. I've also used PHP Sandbox to test it and get no syntax errors, just a blank results box.
How can I fix this so that the calculations actually occur and show on the page?