This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$isMale = false; | |
$isTall = false; | |
if ($isMale && $isTall){ | |
echo "You are a tall male"; | |
} elseif ($isMale && !$isTall){ | |
echo "You are a short male"; | |
} elseif(!$isMale && $isTall){ | |
echo "You are not male but are tall"; | |
} else { | |
echo "You are not male and not tall"; | |
} | |
?> |
↑今回使うコード。
$isMale
$isTall
この二つのデータを、それぞれtrueの時とfalseの時、4パターンに分けられる。
2つともtrueの時
MaleでTallの時は、2つともtrueになり、一番初めのechoが表示される。
if ($isMale && $isTall)
&&が2つのデータを入れる時に使う記号。
isMaleがTrueで、isTallがFalseの時
次のステートメントは、elseifを使って表す。
($isMale && !$isTall)
となり、この!記号がfalse(not)の役割を果たす。
isMaleがFalseで、isTallがTrueの時
先ほどの逆バージョン。
isMaleも、isTallもどちらもFalseの場合
最後の行はelseになり、全てに当てはまらなかった場合は、このデータが表示される。
コメント 作品をシェア!