Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/exercises/

dbtestforfattare.php
exercise_include/
form1_2.php
form3_4.php
form3_4_resultat.php
form_welcome.php
forms_quiz.php
funktioner.php
grunder.php
string4.php
textstrings.php
textstrings_result.php

funktioner.php

75 lines ASCII Windows (CRLF)
<?php
//Uppgift 1
print_r("Hejsvejs");


//Uppgift 2
echo "<br><hr><br>";
function 
hejsvejs($antal){
    for (
$i=0; $i < $antal; $i++){
        
print_r("Hejsvejs");
    }
}
hejsvejs(5);


//Uppgift 3 och 4
echo "<br><hr><br>";
function 
returnBiggest(... $numbers){
    
sort($numbers);
    return 
$numbers[(count($numbers) - 1)];
}
print_r(returnBiggest(4, 9, 7,));


//Uppgift 5
echo "<br><hr><br>";
$array= array(16, 5, 9, 18, 2);
function 
avg($numbers){
    
$sum = 0;
    foreach (
$numbers as $number){
        
$sum += $number;
    }
    return 
$sum / count($numbers);
}
print_r(avg($array));


//Uppgift 6
echo "<br><hr><br>";
$array= array(16, 5, 9, 18, 2, 10);

function 
replaceIfEven($array){
    foreach(
$array as &$element){
        if (
$element % 2 == 0){
            
$element = 0;
        }
    }
    return 
$array;
}

print_r(replaceIfEven($array));


//Uppgift 7
echo "<br><hr><br>";
$array= array(16, 5, 9, 18, 2, 10, 12, 15, 21);
function 
arrayStuff($array){
    
sort($array);
    while (
count($array) > 2){
        
array_pop($array);
        
array_shift($array);
    }
    
$sum = 0;
    foreach(
$array as $element){
        
$sum =+ $element;
    }
    return 
$sum / count($array);
}
print_r(arrayStuff($array));
unset(
$array);




?>