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!"; } ?>