Home > Article > PHP Framework > How to use if not equal statement in thinkphp3.2
In the development of thinkphp3.2, it is often necessary to use if conditional judgment statements to perform different operations. But sometimes, when we need to judge whether it is not equal to a certain value, we need to use the if not equal statement. So, how to use it specifically?
First of all, we need to understand the basic usage of if statements. The if statement usually consists of a conditional expression and one or more statements. When the value of the conditional expression is true, the corresponding statement is executed, otherwise the execution is skipped.
In thinkphp3.2, the syntax of the if statement is similar to that of other languages, as shown below:
if (条件表达式) { // 如果条件表达式的值为true,则执行此处代码 } else { // 如果条件表达式的值为false,则执行此处代码 }
Among them, the conditional expression can be a constant, a variable, an operation expression, etc. etc., as long as the final value is true or false. If statements can also be nested within another if statement.
Let’s now look at the usage of if is not equal to statement. In php, the inequality operator is "!=". Therefore, the syntax of if is not equal to:
if (变量/常量 != 值) { // 如果变量/常量的值不等于指定的值,则执行此处代码 } else { // 如果变量/常量的值等于指定的值,则执行此处代码 }
If you need to judge multiple cases of inequality, you can use the "||" (or) operator to connect multiple judgment statements. For example:
if ($a != 1 || $a != 2) { // 如果$a的值不等于1或2,则执行此处代码 } else { // 如果$a的值等于1或2,则执行此处代码 }
It should be noted that the use of if is not equal to the statement must meet two conditions:
For example, the following code is wrong:
// 此处会产生错误 if ($a =! 1) { // ... }
The correct way to write it should be:
if ($a != 1) { // ... }
Generally speaking, if is not equal to the statement, it can judge multiple One of the more commonly used statements is situation. In actual development, we can use it flexibly as needed to achieve more refined operations.
The above is the detailed content of How to use if not equal statement in thinkphp3.2. For more information, please follow other related articles on the PHP Chinese website!