Les conditions SWITCH permettent d'exécuter certains codes en fonction de la valeur d'une variable passée en paramètre.
PHP : Condition SWITCH avec accolades
<?php
$x = 42;
switch ( $x ) {
case 1:
echo '$x is the one, neo';
break;
case 42:
echo '$x is the answer to the Ultimate Question of Life, The Universe, and Everything';
break;
default:
echo '$x is just a number';
break;
}
?>
PHP : Condition SWITCH sans accolades
<?php
$x = 42;
switch ( $x ) :
case 1:
echo '$x is the one, neo';
break;
case 42:
echo '$x is the answer to the Ultimate Question of Life, The Universe, and Everything';
break;
default:
echo '$x is just a number';
break;
endswitch;
?>