Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/funktioner/

index.php
ovn_fn1 copy.php
ovn_fn1+2.php
ovn_fn3+4.php
ovn_fn5.php
ovn_fn6.php
ovn_fn7.php

ovn_fn7.php

50 lines ASCII 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>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Funktioner</title>
</head>

<body>

    <?php
    $arr 
= [];
    
$arrCount random_int(120000);
    for (
$i 0$i<$arrCount$i++){
        
$arr[] = random_int(09999);
    }
    
    function 
getMedian($arr){
        
sort($arr);
        if (!(
count($arr)%2)){
            
$element1 $arr[count($arr)/2];
            
$element2 $arr[count($arr)/1];
            return(
$element1/$element2/2);
        } else{
            
$index floor(count($arr)/2);
            return(
$arr[$index]);
        }
    }

    function 
writeArr($arr){
        for (
$i 0$i<count($arr);$i++){
            echo(
$arr[$i] . "  ");
        }
        echo(
"<br>");
    }

    echo(
"Median: " getMedian($arr) . "<br>");
    
writeArr($arr);
    
?>

</body>

</html>