PHP operator (vi) Example of "comparison operator" explained

Source: Internet
Author: User
Learning from the preceding series of PHP operators, today we learn the sixth operator of the PHP operator " comparison Operators”。

What is the comparison operator used for?

Comparison operators you literally understand that it is used to compare, it is the result of two variables or expressions of the size, true and false comparison, if the results are true, return true, conversely, if the result of the comparison is false, then return FALSE.

Let's take a look at what the comparison operators in PHP have

Comparison operators

Operator Name Example Description
< Less than $x < $y Returns True if the $x is less than $y.
> Greater than $x > $y Returns True if the $x is greater than $y
<= Less than or equal $x <= $y Returns True if $x is less than or equal to $y.
>= Greater than or equal $x >= $y Returns true if $x is greater than or equal to $y.
== Equal $x = = $y Returns True if the $x equals $y.
!= Range $x! = $y Returns true if $x is not equal to $y
=== Identity (congruent) $x = = = $y Returns True if $x equals $y and they are of the same type
!== Non-identical (not congruent) $x!== $y Returns true if $x are not equal to $y and they are of different types


There are two comparison operators that need attention, which is "= = =" and "! = = ". Using the "= = =" Operator For comparison, not only is the value equal, but also on the data type, for example, $a = = = $b, stating that $ A and $b are not only exactly equal in value, but also the same as the data type of $ A and $b. = = = = = = = = = = = opposite, e.g. $a! = = $b, which means $ A and $b or different numbers or data types.

Comparison operator Instances

This example uses comparison operators to compare the values of variables, set the variable $x=100, the data type is integer, the variable $y= "100", the data type is a string, compares $x and $y, uses "= =", "= = =", "! = ","! = = = operator.

The code is as follows

<?php$x=100; $y = "Var_dump"; ($x = = $y); echo "<br>"; var_dump ($x = = = $y); echo "<br>"; Var_dump ($x! = $y); echo "<br>"; Var_dump ($x!== $y); echo "<br>";? >

Code Run Result:

The other several relatively simple, here do not do too much demonstration, interested can do it yourself, the next section, we will explain the PHP operator seventh "error control operator."

Related articles recommended:

1.PHP operator (i) An example of "arithmetic operator" explained

2.PHP operator (ii) a detailed example of a "string operator"

3.PHP operator (c) "Assignment operator" Example explained

4.PHP operator (iv) "Bitwise operator" Walkthrough

5.PHP operator (v) "logical operator" Instance explained

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.