Php comparison operator

Source: Internet
Author: User
Tags php tutorial

Php Tutorial comparison operator
A comparison operation compares two values to reflect the relationship between two numbers.
Example name result
$ A = $ B is equal to TRUE if $ a is equal to $ B.
$ A ===$ B all equal to TRUE, if $ a is equal to $ B, and their types are the same.
$! = $ B is not equal to TRUE, if $ a is not equal to $ B.
$ A <> $ B is not equal to TRUE, if $ a is not equal to $ B.
$! = $ B is not equal to TRUE. If $ a is not equal to $ B, or they have different types.
$ A <$ B small and TRUE, if $ a is strictly less than $ B.
$ A> $ B is greater than TRUE if $ a is strict with $ B.
$ A <= $ B is less than or equal to TRUE, if $ a is less than or equal to $ B.
$ A >=$ B is greater than or equal to TRUE if $ a is greater than or equal to $ B.

<? Php
$ A = 10;
$ B = 10;
Echo $ a = $ B; // $ a = $ B? 10 = 10 returns 1 True
Echo "<br/> ";

Echo $ a ===$ B; // $ a ===$ B? 10 = 10 returns 1 True
Echo "<br/> ";

$ B = "10 ";
Echo $ a ===$ B; // $ a ===$ B? 10 = "10" return null false to compare two data types, not only the data value but also the data type;
Echo "<br/> ";

$ A = 10;
$ B = 20;
Echo $! = $ B; // $ a is not equal to $ B 10! = 20 returns 1 True
Echo "<br/> ";

Echo $ A <> $ B; // $ a is not equal to $ B 100 <> 20. Return 1 True.
Echo "<br/> ";
 
Echo $! ==$ B; // $ a is not equal to $ B, or they have different types. 10! = 20 returns 1 True
Echo "<br/> ";

$ C = "10 ";
Echo $! ==$ C; // non-full equality $ a is not equal to $ B, or they have different types. 10! = "10" return null false
Echo "<br/> ";

Echo $ A <$ B; // $ a must be less than $ B 10 <20 returns 1 True
Echo "<br/> ";

Echo $ A> $ B; // $ a must be less than $ B 10> 20. Return null false.
Echo "<br/> ";

Echo $ A <= $ B; // $ a less than or equal to $ B 10 <= 20 returns 1 True
Echo "<br/> ";

Echo $ A >=$ B; // $ a is greater than or equal to $ B 10 >=20 returns null false
Echo "<br/> ";
?>

Comparison of multiple types of operations 1 type of operations 1 type of results
Null or string converts NULL to "" for comparison of numbers or words
Bool or null any other type is converted to bool, FALSE <TRUE
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.
Array has a small array of fewer members. If the key in Operation Number 1 does not exist in Operation Number 2, the array cannot be compared; otherwise, the values are compared one by one (see the following example)
Array any other type of array is always larger
Any other object type of 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.