PHP Switch 语句
switch (n) { case label1: 如果 n=label1,此处代码将执行; break; case label2: 如果 n=label2,此处代码将执行; break; default: 如果 n 既不等于 label1 也不等于 label2,此处代码将执行; }
代码:
<?php $favcolor="red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, or green!"; } ?>