PHP comparison operator

Source: Internet
Author: User

 

From: http://php.chinaunix.net/manual/zh/language.operators.comparison.php

 

 

Example Name Result
$ A = $ B Equal TrueIf $ A is equal to $ B.
$ A ===$ B Full TrueIf $ A is equal to $ B, and their types are the same. (Introduced in PHP 4)
$! = $ B Not Supported TrueIf $ A is not equal to $ B.
$ A <> $ B Not Supported TrueIf $ A is not equal to $ B.
$! ==$ B Incomplete TrueIf $ A is not equal to $ B, or they are of different types. (Introduced in PHP 4)
$ A <$ B Xiaohe TrueIf $ A is strictly less than $ B.
$ A> $ B Greater TrueIf $ A is strict with $ B.
$ A <= $ B Less than or equal TrueIf $ A is less than or equal to $ B.
$ A> = $ B Greater than or equal TrueIf $ A is greater than or equal to $ B.

 

If you compare an integer with a string, the string is converted to an integer. Compare two numeric strings as integers. This rule also applies to switch statements.

 

For multiple types, comparison operators are compared according to the following table (in order ).

 

Compare multiple types
Operation Number 1 Type Operation Number 1 Type Result
Null or string String SetNullConvert to "" For comparison of numbers or words
Bool or null Any other type Convert to bool,False<True
Object Object Built-in classes can define their own comparisons. Different classes cannot be compared. The same classes and arrays are used to compare attributes (in PHP 4). PHP 5 has its own instructions.
String, resource, or number String, resource, or number Converts a string and a resource to a number and compares it by common mathematics.
Array Array The array with fewer members is small. If the key in Operation Number 1 does not exist in Operation Number 2, the array cannot be compared. Otherwise, compare the values one by one (see the following example)
Array Any other type Array is always larger
Object Any other type The object is always larger.

 

 

 

 

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.