Prior to doing the project encountered a problem, the code is roughly as follows:
Switch ($a) {case $a >=1000 && $a <5000:echo "vip1"; Break Case $a >=5000 && $a <=10000:echo "VIP2"; Break Default:echo "Vipx";
If $ A >0 is not a problem, when $ A =0, the problem will come, the program will output: VIP1;
Later, it should be the following:
The function of switch in PHP is: Choose to execute a block of code, which works as follows:
1. A one-time calculation of expressions (usually variables);
2. Compare the value of the variable with the value of case in the switch structure;
3. If the value of the variable is equal to the value of the case, the code associated with it is executed;
4. When the code finishes executing, the break statement prevents the code from jumping into the next case to continue execution;
5. If there is no case condition to match, execute the code in default;
Instance code:
That is, when $ A =0, the first case first operation, $a >=1000 && $a <5000 Of course is false, and then 0 vs. false, which is true, so returned "VIP1";
This article is from the "7804265" blog, please be sure to keep this source http://7814265.blog.51cto.com/7804265/1820801
PHP Switch Understanding