Switchifelse is used to analyze the efficiency difference and applicability of the switch and ifelse in php. The difference in efficiency and applicability of switch and ifelse in php. switchifelse This article analyzes the differences in efficiency and applicability of switch and ifelse in php. Share it with you for your reference. With the difference in efficiency and applicability of switch and ifelse in php, switchifelse
This article analyzes the efficiency differences between the switch and ifelse in php and their applicability. Share it with you for your reference. The specific analysis is as follows:
Both methods in PHP are used to determine whether the value meets the conditions. if the value Meets/does not meet the conditions, different actions are performed.
No matter what language programs are written, the code running efficiency will be taken into account. After reading some materials, switch and ifelse have different efficiency advantages in different 'environment.
1. when the determined value is a constant (fixed value), the switch operation efficiency is higher than the ifelse operation efficiency;
$ Changliang = 3; // The variable judgment value is constant switch ($ changliang) {case 1: echo 'constant value is 1'; break; // jump out of loop case 2: echo 'constant value: 2'; break; case 3: echo 'constant value: 3'; break ;}
2. when the determined value is a variable, ifelse runs more efficiently than switch. ifelse implements the final judgment policy and starts to judge from the first condition until the last else, therefore, it is advantageous to learn to use a switch;
$ A = $ _ GET ['A']; // get the value after passing the value through GET; if ($ a = 1) {echo 'variable a value is 1';} elseif ($ a = 2) {echo 'variable a value is 2';} elseif ($ a = 3) {echo 'the value of variable a is 3';} else {echo 'the value of variable a is unknown ';}
I hope this article will help you with php programming.
In this article, the efficiency difference and applicability of switch and ifelse in php are analyzed. Share it with you for your reference. With...