Comparison Operators and logical operators may be used in models, operations, and templates of ThinkPHP. some of them can directly use PHP operators, while some must use ThinkPHP-specific operators. Beginners are often confused about this. This article describes the comparison operators and logical operators in ThinkPHP in detail.
Comparison Operators and logical operators may be used in ThinkPHP models, operations, and templates.
In some cases, ThinkPHP-specific operators must be used. Beginners are often confused about this. This article focuses on ThinkPHP.
In this section, we will give a detailed introduction to the use of comparison operators and logical operators.
Use operators in operations
Use the PHP operator
In the operation, General logical code snippets can be used directly.
Operators in PHP, such:
- Public function index (){
- If (intval ($ _ GET ['id'])> 0 ){
- Echo 'Id parameter valid ';
- }
- }
Use the ThinkPHP operator
When performing database operations, you must use
ThinkPHP operator:
- Public function index (){
- // Uid <= 5
- $ Condition ['uid'] = array ('elt', 5 );
- $ List = $ Dao-> where ($ condition)-> select ();
- }
If you use:
$ Condition ['uid'] <=
5;
This is obviously an incorrect syntax, and the following usage is also incorrect (an expression error will be prompted ):
$ Condition ['uid'] =
Array ('<=', 5 );
The only exception is that the value assignment operation (=) can be used directly:
$ Condition ['uid'] =
5;
Prompt
The where condition can also be passed in as a string. in this case, the PHP operator is used directly:
$ List =
$ Dao-> where ('uid <= 5')-> select ();
Use operators in the template
Must be used in the template
ThinkPHP operator. Note that it is necessary to use the template to determine the tag, not to say that no PHP operator is allowed in the template.
For example
ThinkPHP operator:
In addition, the comparison label in the template has the same meaning as the operator:
Value = "10"> value
Comparison between ThinkPHP and PHP operators
ThinkPHP tag, description and corresponding PHP tag and remarks
Eq
Equal to (=) (=: used for template judgment) can be used for query conditions and template judgment
Neq is not equal (! =) Can be used for query conditions and template judgment
Gt greater than (>)
It can be used to determine query conditions and templates.
Egt greater than or equal to (> =) can be used for query conditions and template judgment.
<Less than (<) can be used for query conditions and template judgment
Elt
Less than or equal to (<=) can be used for query conditions and template judgment
Heq constant equals (=) can be used for template judgment
Nheq is not always equal (! =)
Can be used for template judgment
AND logic AND (&) can be used for query conditions
OR logic OR (|)
Available for query conditions
Read more
PHP operators
ThinkPHP comparison Tag
ThinkPHP If
Tag
ThinkPHP Where condition