Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/funktioner/
ovn_funk1.php
ovn_funk2.php
ovn_funk3.php
ovn_funk4.php
ovn_funk5.php
ovn_funk6.php
ovn_funk7.php
ovn_funk8.php
ovn_funk7.php
36 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Övning funktioner 7</title>
</head>
<body>
<?php
function listaMedel(...$lista) {
$tot = 0;
for($i=0; $i<count($lista); $i++) {
$tot += $lista[$i];
}
return $tot/count($lista);
}
function listaMedian(...$lista) {
sort($lista);
if (count($lista)%2 ==0) {
return $lista[( (count($lista)/2) + ((count($lista)/2)+1) ) / 2];
}
else{
return $lista[ceil(count($lista)/2)];
}
}
echo "Medelvärde: ". listaMedel(3,8,3,7,100,9,29,499,44);
echo "<br>";
echo "Median: ". listaMedian(3,8,3,7,100,9,29,499,44);
?>
</body>
</html>