23 lines
483 B
PHP
23 lines
483 B
PHP
|
<?php
|
||
|
|
||
|
function calculatrice($a, $b, $operateur) {
|
||
|
switch($operateur) {
|
||
|
case "+":
|
||
|
return $a + $b;
|
||
|
case "-":
|
||
|
return $a - $b;
|
||
|
case "*":
|
||
|
return $a * $b;
|
||
|
case "/":
|
||
|
return $a / $b;
|
||
|
case "%":
|
||
|
return $a % $b;
|
||
|
default:
|
||
|
return "Opérateur non reconnu";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Exemple d'utilisation de la fonction
|
||
|
$resultat = calculatrice(5, 3, "+");
|
||
|
echo "5 + 3 = " . $resultat;
|