PHP interesse |
|
<?php
function calc($getal1, $getal2, $test){
if($test == "optellen"){
echo $getal1 + $getal2;
}
elseif($test == "aftrekken"){
echo $getal1 - $getal2;
}
elseif($test == "delen"){
echo $getal1 / $getal2;
}else{
echo $getal1 * $getal2;
}
}
calc("10","5","aftrekken");
echo "<br>";
calc("10","5","optellen");
echo "<br>";
calc("10","5","delen");
?>
<?php function calc($getal1, $getal2, $test){ if($test == "optellen"){ } elseif($test == "aftrekken"){ } elseif($test == "delen"){ }else{ } } calc("10","5","aftrekken"); calc("10","5","optellen"); calc("10","5","delen"); ?>
zoiets?
edit: met een form:
<?php
function calc($getal1, $getal2, $test){
if($test == "optellen"){
echo $getal1 + $getal2;
}
elseif($test == "aftrekken"){
echo $getal1 - $getal2;
}
elseif($test == "delen"){
echo $getal1 / $getal2;
}else{
echo $getal1 * $getal2;
}
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$nr1 = $_POST['nr1'];
$nr2 = $_POST['nr2'];
$berekening = $_POST['berekening'];
calc("$nr1","$nr2","$berekening");
}else{
?>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="nr1">
<select name="berekening">
<option value="optellen">optellen</option>
<option value="aftrekken">aftrekken</option>
<option value="delen">delen</option>
</select>
<input type="text" name="nr2"><br>
<input type="submit" value="bereken">
</form>
<?
}
?>
<?php function calc($getal1, $getal2, $test){ if($test == "optellen"){ } elseif($test == "aftrekken"){ } elseif($test == "delen"){ }else{ } } if($_SERVER['REQUEST_METHOD'] == 'POST'){ $nr1 = $_POST['nr1']; $nr2 = $_POST['nr2']; $berekening = $_POST['berekening']; calc("$nr1","$nr2","$berekening"); }else{ ?> <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" name="nr1"> <select name="berekening"> <option value="optellen">optellen</option> <option value="aftrekken">aftrekken</option> <option value="delen">delen</option> </select> <input type="text" name="nr2"><br> <input type="submit" value="bereken"> </form> <? } ?>
|