php 流程控制switch的简单实例,phpswitch
switch允许对一个标量(表达式)的多个可能结果做选择。
语法:
switch (expr) { case result1: statement1 break; case result2: statement2 break; …… default: statement }
系统计算expr的值,根据计算结果(result1、result2等)来选择下面对应执行语句,如果所有的case结果都不符合,则会执行default里的语句。
例子:
<?php switch ($x) { case 0: echo "x 等于 0"; break; case 1: echo "x 等于 1"; break; case 2: echo "x 等于 2"; break; default: echo "x 既不等于1和2,也不等于0"; } ?>
提示
•可以有多个 case 条件判断
•case 后面结果也不是仅限于数字,也可以是字符或其他 PHP 支持的类型
•default 不是必须的
以上这篇php 流程控制switch的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持帮客之家。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool