Differences and applications in php (equal to and full) = and =

Source: Internet
Author: User
In php, the average is equal to the full expression. in simple terms, it is a simple equivalent. In other words, it is very precise. next I will introduce it to you.

In php, the average value is equal to the total value. in expression test, the value is equal to = and =. in simple terms, the value is a simple value, next, I will introduce the differences and applications between = and =. For more information, see.

In php, the symbols are equal to '=' and all equal to '='. on the surface, they both determine whether the two equal signs are equal, but one is two equal signs, one is the third equal sign.

We should all know that php is a weak type of statement, and its variables and character definitions are not very standard, such as $ a = '4 ′; we can say that $ a is a character, but it can directly perform addition, subtraction, multiplication, division, and division of numbers. In addition, we also know that a single sentence is called a non-zero sign (true, so this sentence is good for the = symbol.

The instance code is as follows:

  1. If (4! = False) {echo 'OK '},

This judgment is true, and it will output OK. because 4 is not zero, it is true. true is not equal to false. Therefore, if the judgment is true, OK is output, in fact, when determining the comparison, 4 is converted to a Boolean value true due to the object comparison reason. of course, if you use = here, it is also true.

The instance code is as follows:

  1. If (4! = False) {echo 'OK '}

He will also output OK, because 4 is not false, they are not the same character, but there is a very important difference between the two, that is, = or! = Is converted to the character type because of the object to be compared, and = or! = Is to force him to compare without conversion, for example, the following example:

The instance code is as follows:

  1. If (0! = False) {echo 'OK '}

This will not output OK, because 0 is false, the judgment is not true, but if you write

The instance code is as follows:

  1. If (0! = False) {echo 'OK '}
This judgment is true and OK is output, because if 0 is not converted, it is not false, and 0 is 0;

The instance code is as follows:

  1. If ('4 ′! = 4) {echo 'OK '}

This will not output OK, because after the conversion is equal, the judgment is not true, but if it is

The instance code is as follows:

  1. If ('4 ′! = 4) {echo 'OK '};

This will output "OK" and "true", because in front of "constant", "4" with single quotation marks and "4" without single quotation marks are not the same "4". one is a number and the other is a character. so it seems that their comparison is very simple. what practical applications do they use. for example:

The instance code is as follows:

  1. If (strpos ('ABC', 'A ')! = False) {echo 'OK '};

The instance code is as follows:

Related Article

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.