Comparison Operators and logical operators in ThinkPHP

Source: Internet
Author: User
Tags php operator
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:




  1. Public function index (){
  2. If (intval ($ _ GET ['id'])> 0 ){
  3. Echo 'Id parameter valid ';
  4. }
  5. }

Use the ThinkPHP operator

When performing database operations, you must use
ThinkPHP operator:




  1. Public function index (){
  2. // Uid <= 5
  3. $ Condition ['uid'] = array ('elt', 5 );
  4. $ List = $ Dao-> where ($ condition)-> select ();
  5. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.