- <html>
- <head>
- <title>switch 特殊寫法</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <?php
- date_default_timezone_set('Asia/Taipei'); //Asia/Taipei America/New_York Pacific/Honolulu Europe/London
- switch(date("H")):
- case 5; //分號也是可以執行
- case 6;
- case 7;
- case 8;
- case 9:
- case 10:
- case 11:
- echo "Good Morning!<p/>";
- break;
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- echo "Good Afternoon!<p/>";
- break;
- case 17:
- case 18:
- case 19:
- case 20:
- echo "Good Evening!<p/>";
- break;
- default:
- echo "Good Night!<p/>";
- endswitch;
- echo date('D, F j, Y, H:i:s A');
- ?>
- </body>
- </html>
複製代碼 |