Comment faire que cette instruction if fonctionne pour 0, 1 et 2 chats?PHP: Si/elseif/else instruction incorrecte meilleure méthode?
Lorsque $ chats = 0 ou 1, il ECHOS "Il est bien que vous avez seulement 2 chats"
Toute suggestion de code?
<?php
//If you have more then 2 cats it is illegal
//if you have 20 or more cats "you are a freak!"
//If you have 2 cats "It is fine you only have 2 cats".
//If you have 1 cats "It is fine you only have 1 cat".
//If you have 0 cats "You don't have any cats no problem".
$cats = 25;
if ($cats > 2 && $cats < 20){
echo "You have too many cats, it is illegal!";
} elseif ($cats >= 20) {
echo "you are a freak!";
} elseif ($cats = 2) {
echo "It is fine you only have 2 cats";
} elseif ($cats = 1) {
echo "It is fine you only have 1 cat";
} elseif ($cats = 0){
echo "You don't have any cats no problem";
}
?>
Oui, je passe juste par CodeCademy c'est la réponse évidente. – Josh