Webbserverprogrammering 1

Källkod

Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.

webbserverprogrammering/exercises/functions/

9 filer

functions_1.php
functions_2.php
functions_3.php
functions_4.php
functions_5.php
functions_6.php
functions_7.php
functions_8.php
functions_9.php

functions_7.php

36 lines UTF-8 Windows (CRLF)
<?php
error_reporting
(-1); // Report all type of errors
ini_set('display_errors'1); // Display all errors 
ini_set('output_buffering'0); // Do not buffer outputs, write directly
?>

<!DOCTYPE html>
<html lang="sv">
<head>
 <title>Funktioner 7</title>
</head>
<body>
 <?php
  $numbers 
= [12473015];

  
print_r($numbers);
  echo 
"<br><br>";

  echo 
"Medianvärde: " returnMedian($numbers);

  function 
returnMedian($array) {
   
sort($array);
   
$middleIndex count($array) / 2;

   if (
count($array) % !== 0) {
    
// Median:
    
return $array[$middleIndex];
   }
   else {
    
$evenArrayMedian = ($array[$middleIndex 1] + $array[$middleIndex]) / 2;
    return 
$evenArrayMedian;
   }
  }
 
?>
</body>
</html>