Get the App
SLTechnology News&Howtos  ›  Development  › 

In PHP = = how to use it

Shulou Source: shulou.com Published: 2022-06-03 06:14:58 10月24日 Update

This article will explain in detail how to use PHP = =. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The frequency of the PHP comparison operator is too high, especially the = =

If (a = = b) {

/ / do something

}

But have you really mastered "="? Details are important!

Take a look at the following code and say what you think is the right answer

Var_dump ('123fg456'==123)

Var_dump ('some string' = = 0)

Var_dump (123.0 = '123d456')

Var_dump (0 = "a")

Var_dump ("1" = = "01")

Var_dump ("1" = = "1e0")

Figure out your answer first, and then run it again. If the answer is not wrong, then congratulations, the basic knowledge is very solid.

Explanation:

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

In particular, when a string is converted to an integer, it is from left to right until a non-numeric character is encountered. That means' 123abc456 'will be converted to 123 instead of 123456. In addition, the space at the beginning of the string is ignored, such as converting '234abc' to 234.

A comparison table of loose comparison and strict comparison is attached below.

This is the end of the article on "how to use PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Characters strings integers answers articles numbers more knowledge good practical solid loose important two that is code content basics basics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Shulou Information Xiaomi Shulou Technology