Home php教程 php手册 PHP4实际应用经验篇(7)

PHP4实际应用经验篇(7)

Jun 21, 2016 am 09:03 AM
break case Fortune gt switch

另一种和 "if-else"家族控制语句功能几乎相同的是PHP的"switch"语句。它看起来如下所示:


--------------------------------------------------------------------------------
switch (决定变量)
{
case 第一个条件正确:
do this!

case 第二个条件正确:
do this!

case 第三个条件正确:
do this!

... 等等...

}
--------------------------------------------------------------------------------
  我们将通过使用"switch" 语句重写上面的幸运甜饼例子来把这些说明的更清楚一些:

[cookie.php]

--------------------------------------------------------------------------------

// 这里的决定变量是用户选择的日期
switch ($day)
{

// 第一种情况
case "Monday":
$fortune = "当能找到使每件事做的复杂精彩的方法的时候,不要使它简单有效";
break;

// 第二种情况
case "Tuesday":
$fortune = "生活是游戏的桥梁?-你一定施展某种巧计了。";
break;
// 第三种情况
case "Wednesday":
$fortune = "什么能使头脑清醒的人生活在这个世界上永不发疯?";
break;
// 第四种情况
case "Thursday":
$fortune = "不要疯狂,要有趣";
break;
// 第四种情况
case "Friday":
$fortune = "仅仅跟着时代走,顺着风气行,当你得到提升时你会发现类型是个魔鬼。";
break;


// 如果以上条件都不符合...
default:
$fortune = "很抱歉,周末关门";
break;

}

?>







这是您的幸运语:





--------------------------------------------------------------------------------
  有两个重要的关键字:关键字"break"用来打断 "switch" 语句结构并且立即移到结构块外面,然后运行块后面紧跟着的行。 "default" 关键字用来执行当传给 "switch" 的变量都不符合语句结构中所列举的任何一种情况时所设定的语句。



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

What are the differences between the Japanese and Hong Kong versions of switch? What are the differences between the Japanese and Hong Kong versions of switch? Jun 20, 2023 pm 02:06 PM

Differences between the Japanese version of the switch and the Hong Kong version: 1. There are major differences in the charger. The Japanese version and the national standard charging port are common, and the Hong Kong version uses a British triangle plug; 2. The Japanese version uses point card payment, while the Hong Kong version uses Alipay; 3. , The after-sales warranty for the Hong Kong version needs to be mailed back to the HK after-sales point, while the Japanese version needs to be mailed to the designated after-sales point in Japan.

What should I do if the switch does not respond to the TV? What should I do if the switch does not respond to the TV? Jul 03, 2023 am 11:15 AM

Solution for the switch not responding to the TV: 1. Check whether the power supply of the switch and the TV are connected; 2. Check whether the TV HDMI cable interface is plugged in tightly; 3. Open the back cover of the Switch base and check whether the power cord and HDMI cable are plugged in tightly; 4. Check whether the Switch is turned on and put into the base; 5. Check whether the TV has switched the signal source.

Can Elden's Ring be played on switch? Can Elden's Ring be played on switch? Mar 11, 2024 am 11:31 AM

Can Elden's Ring be played on the switch? As a very charming action RPG game, many friends may not know whether it can be played smoothly on the switch platform. The answer is that it cannot be played at the moment. accomplish. Can Ring of Elden be played on switch? Answer: It cannot be played on switch. This highly anticipated Souls series role-playing action game has been officially released. Players can purchase it on PC, PS4/5 and Xbox Series eX|S/XboxOne and experience it immediately. Many friends who own a switch may still be eager to enjoy this game on the NS, but unfortunately, there is no switch version of the game. According to the official website configuration requirements, the game configuration is relatively high, and sw

Can the switch be charged on the base all the time? Can the switch be charged on the base all the time? Jul 06, 2023 pm 04:51 PM

The switch cannot be charged on the base all the time. The hazards are: 1. Shortening the battery life and battery life; 2. Cause the memory to burn out.

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Does switch32g have enough memory? Does switch32g have enough memory? Jun 20, 2023 pm 02:28 PM

The memory of switch32g is not enough. The reasons are as follows: 1. If you buy digital games and want to buy DLC screenshots and store them in the handheld machine, it is not enough. 2. When downloading digital games, 32G memory can store about 2 to 3 games, which is not enough. The need to play games; 3. Digital games and their DLC are generally maintained on 5G. Except for the space occupied by the built-in system, downloading games is more difficult for players.

What is the difference between switch lite and switch What is the difference between switch lite and switch Jun 28, 2023 pm 02:13 PM

The differences between switch lite and switch are: 1. Different sizes; 2. Different screen sizes and body weights; 3. Different handles whether they are detachable and different handle functions; 4. Different battery life; 5. Different handle button designs; 6. Can Support different games; 6. Different colors.

See all articles