Home > PHP Framework > ThinkPHP > How to use if not equal statement in thinkphp3.2

How to use if not equal statement in thinkphp3.2

PHPz
Release: 2023-04-07 10:41:44
Original
1234 people have browsed it

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,则执行此处代码
}
Copy after login

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 {
    // 如果变量/常量的值等于指定的值,则执行此处代码
}
Copy after login

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,则执行此处代码
}
Copy after login

It should be noted that the use of if is not equal to the statement must meet two conditions:

  1. Variables/constants must be defined first, otherwise an error will occur;
  2. The inequality operator must precede the equality operator "=".

For example, the following code is wrong:

// 此处会产生错误
if ($a =! 1) {
    // ...
}
Copy after login

The correct way to write it should be:

if ($a != 1) {
    // ...
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template