Created
April 10, 2013 16:30
-
-
Save hirak/5356212 to your computer and use it in GitHub Desktop.
switch文の使いどころの悩み ref: http://qiita.com/items/af2b304650272410ec29
This file contains hidden or 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 | |
switch (true) { | |
case 0: | |
echo '数字の0'; | |
break; | |
case '0': | |
echo '文字列の0'; | |
break; | |
case '0.0': | |
echo '文字列の0.0'; | |
break; | |
case true: | |
echo '真偽値のtrue'; | |
break; | |
} |
This file contains hidden or 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 | |
if ($_GET['hoge'] === 'foo' || $_GET['hoge'] === 'moo' || $_GET['hoge'] === 'soo') { | |
//... | |
} elseif ($_GET['hoge'] === 'baa' || $_GET['hoge'] === 'buu') { | |
//... | |
} |
This file contains hidden or 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 | |
switch ($_GET['hoge']) { | |
case 'foo': case 'moo': case 'soo': | |
//... | |
break; | |
case 'baa': case 'buu': | |
//... | |
break; | |
} |
This file contains hidden or 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 | |
if (in_array($_GET['hoge'], ['foo', 'moo', 'soo'], true)) { | |
//... | |
} elseif (in_array($_GET['hoge'], ['baa', 'buu'], true)) { | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment