php switch
A switch statement is like a series of if statements with the same expression. There are many situations where you need to compare the same variable (or expression) with many different values and execute different code depending on which value it equals.
Example
<?php switch (n) { case label1: 如果 n=label1,此处代码将执行; break; case label2: 如果 n=label2,此处代码将执行; break; default: 如果 n 既不等于 label1 也不等于 label2,此处代码将执行; } //类似于下面示例 if ($i == 0) { echo "i equals 0"; } elseif ($i == 1) { echo "i equals 1"; } elseif ($i == 2) { echo "i equals 2"; } ?>
Recommended tutorial: "PHP Video Tutorial"
The above is the detailed content of Detailed explanation of php switch method examples in PHP. For more information, please follow other related articles on the PHP Chinese website!