Home > Backend Development > PHP Tutorial > PHP process control switch instance, PHP process switch instance_PHP tutorial

PHP process control switch instance, PHP process switch instance_PHP tutorial

WBOY
Release: 2016-07-12 08:51:18
Original
731 people have browsed it

php process control switch instance, php process switch instance

switch allows selection of multiple possible results of a scalar (expression).

Syntax:

switch (expr) {
    case result1:
    statement1
    break;
    case result2:
    statement2
    break;
    ……
    default:
    statement
}
Copy after login

The system calculates the value of expr and selects the corresponding execution statement below based on the calculation results (result1, result2, etc.). If all case results do not match, the statement in default will be executed.

Example:

<?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";
}
?>
Copy after login

Run

Tips

  • There can be multiple case conditional judgments
  • The result after the case is not limited to numbers, but can also be characters or other types supported by PHP
  • default is not required

Original address: http://www.manongjc.com/php/php_if_switch.html

Related reading:

php getdate() gets the current time year, month, day, hour, minute, second and week

php date() format date and time

php date_sunset() gets the sunset time

php date_sunrise() gets the sunrise time based on the location (latitude and longitude)

php global legal time zone list

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1131875.htmlTechArticlephp process control switch instance, php process switch instance switch allows multiple possible results for a scalar (expression) Make a choice. Syntax: switch (expr) { case result1: statement1...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template