In the PHP equivalent judgment, the difference between constants and variables on the left and right

In the process of writing code at ordinary times, it is often used to judge the equality of variables and constants, such as if($a==1){…..} or if(1==$a), in terms of execution efficiency, 1 ==$a is more efficient than $a==1.

Another advantage of this writing,When using the == operator to compare variables and constants of a certain type, it is better to write the constant to the left of the "==" operator, such as 'A'==word, so that if you accidentally put "==" Written as "=", it becomes 'A'=word, then the compiler will give an error message. And if it is written as word='A', this is a normal assignment statement. The assignment is successful and returns true. Of course, this should not be what you originally meant, so a logical error will occur.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325212354&siteId=291194637