Differences between = and = in php _ PHP Tutorial

Source: Internet
Author: User
Difference analysis between php and. The difference between the constant operator and the comparison operator "" is that "" does not check the type of conditional expressions. the constant operator checks the value and type of expressions at the same time. This is mainly different from the ph constant operator and the comparison operator "=", that is, "=" does not check the type of conditional expressions, the constant operator checks the value and type of the expression at the same time.

This is mainly related to php non-type languages, such as NULL, FALSE, array (), "", 0, "0". if they are equal to =, however, if you determine the true return value of a value, you can use =
$ A = 0;
$ B = FALSE;
$ A = FALSE is not true, but $ B = FALSE is true. If yes, $ a = FALSE and $ B = FALSE are both true.

The ===operator is still very useful. some built-in functions in php return a value if they succeed, and false if they fail, if it succeeds but the return value is a null value such as "" or 0, how do you determine the success or failure? You can use = to distinguish variable types.

Refer:

Comparison Operators

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.

The code is as follows:

Var_dump (0 = "a"); // 0 = 0-> true

Var_dump ("1" = "01"); // 1 = 1-> true

Var_dump ("1" = "1e0"); // 1 = 1-> true

Switch (""){

Case 0:

Echo "0 ";

Break;

Case "a": // never reached because "a" is already matched with 0

Echo "";

Break;

}

?>

Condition "=" does not check the type of conditional expressions. constant operator checks the value and type of expressions at the same time. This is mainly used with ph...

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.