Write a program in PHP that loads in an array
I have this:
}
for ($x=0;$x<count($valores);$x++)
Write a program in PHP that loads in an array
I have this:
}
for ($x=0;$x<count($valores);$x++)
<?php
function MediaPositiva ($arr,$mediaFunc)
{
$retArr = array();
for ($i=0; $i <count($arr) ; $i++)
{
if($arr[$i] >$mediaFunc)
{
array_push($retArr,$arr[$i]);
}
}
return $retArr;
}
$res = array();
$valores = array();
for ($x=0;$x<30;$x++)
{
$num_aleatorio = rand(1,10);
array_push($valores,$num_aleatorio);
}
$media = array_sum($valores) / count($valores);
$res = MediaPositiva($valores,$media);
echo '<h4>Las notas mayores a '.$media.' son: </h4><br>';
$y = 1;
for ($i=0; $i <count($res) ; $i++)
{
echo '<label>'.$y.'.-Esta nota es de: '.$res[$i].'</label><br>';
$y++;
}
echo '<h4>Se descartaron '.(count($valores) - count($res)).' notas</h4>';
?>
I recommend that you add more fuel to the next one. Do not forget to mark it as correct if it serves you.