Examples of common expressions in the Where condition of ThinkPHP (detailed description), thinkphpwhere
Where condition expression format:
$ Map ['field name'] = array ('expression', 'Operation condition ');
$ Map is a common array variable and can be named as needed. The expression in the preceding format actually indicates the meaning of the operator:
Comparison between ThinkPHP and SQL Operators
| TP Operator |
SQL Operators |
Example |
Actual query Conditions |
| Eq |
= |
$ Map ['id'] = array ('eq ', 100 ); |
Equivalent to: $ map ['id'] = 100; |
| Neq |
! = |
$ Map ['id'] = array ('neq', 100 ); |
Id! = 100 |
| Gt |
> |
$ Map ['id'] = array ('gt', 100 ); |
Id> 100 |
| Egt |
> = |
$ Map ['id'] = array ('egt', 100 ); |
Id & gt; = 100 |
| Lt |
< |
$ Map ['id'] = array ('lt ', 100 ); |
The id <100 |
| Elt |
<= |
$ Map ['id'] = array ('elt', 100 ); |
Id <= 100 |
| Like |
Like |
$ Map <'username'> = array ('like', 'admin % '); |
Username like 'admin %' |
| Between |
Between and |
$ Map ['id'] = array ('between', '1, 8 '); |
Id BETWEEN 1 AND 8 |
| Not |
Not between and |
$ Map ['id'] = array ('not between', '1, 8 '); |
Id not between 1 AND 8 |
| In |
In |
$ Map ['id'] = array ('in', '1, 5, 8 '); |
Id in (1, 5, 8) |
| Not in |
Not in |
$ Map ['id'] = array ('not in', '1, 5, 8 '); |
Id not in (1, 5, 8) |
| And (default) |
And |
$ Map ['id'] = array ('gt ', 1), array ('lt', 10 )); |
(Id> 1) AND (id <10) |
| Or |
Or |
$ Map ['id'] = array ('gt ', 3), array ('lt', 10), 'or '); |
(Id> 3) OR (id <10) |
| Xor (exclusive or) |
Xor |
If only one of the two inputs is true, the result is true. Otherwise, the result is false. The example is omitted. |
1 xor 1 = 0 |
| Exp |
Comprehensive expression |
$ Map ['id'] = array ('exp ', 'in (1, 3, 8 )'); |
$ Map ['id'] = array ('in', '1, 3, 8 '); |
Additional instructions
• Like SQL, ThinkPHP operators are case-insensitive and eq is the same.
• The between and in conditions support strings or arrays. The following two statements are equivalent:
$map['id'] = array('not in','1,5,8');$map['id'] = array('not in',array('1','5','8'));
Exp expression
Exp in the above table is not an operator, but a comprehensive expression to support more complex condition settings. Exp operation conditions are not treated as strings. You can use any syntax supported by SQL, including using functions and field names.
Exp is used not only for where conditions, but also for data updates, such:
$ Dao = M ("Article"); // construct the save data array. The number of clicks in the document + 1 $ data ['id'] = 10; $ data ['counter'] = array ('exp ', 'counter + 1'); // save the modified data according to the conditions $ User-> save ($ data );
The common expression examples in the above ThinkPHP Where condition (detailed description) are all the content shared by the editor. I hope you can give us a reference and support for the customer's house.