Php,! = B and! What is the difference between a = B?

Source: Internet
Author: User
Tags php operator type null
Sometimes, if (! AB) and if (! B) Actually, there is a difference. I used the previous method several times to get the desired result. I would like to ask the difference between the two. Supplement: Sorry, I wrote an error. It should be! B And! Is there any difference between AB? (Isn't it the same before, because... sometimes you will find if (! A = B) And if (! = B) actually there is a difference;
Several times I used the previous method to get the desired result. I would like to ask the difference between the two.

Supplement:
Sorry, I wrote an error.
It should be! = B and! Is there a difference between a = B?
(Was it because I wrote a mistake ?!)

Reply content:

Sometimes, if (! A = B) And if (! = B) actually there is a difference;
Several times I used the previous method to get the desired result. I would like to ask the difference between the two.

Supplement:
Sorry, I wrote an error.
It should be! = B and! Is there a difference between a = B?
(Was it because I wrote a mistake ?!)

The landlord wrote an error, right? Note:! $a == $b, No! $a = $b

Although the PHP operator priority!Priority higher=But a strange syntax is! $a = $bIn this case$bAssigned$a, And then! $a, Then this statement will always return$b == falseSame result. And$a != $bIt cannot be compared.

While! $a == $bAnd$a != $bSame...

In addition, according to my understanding! $a == $bAnd$a != $bThe results are the same. I didn't think of a special case for the time being. However, many values in PHP can have the same meaning as Boolen. It is inevitable that some of the special situations you say occur during the conversion. List the situations where PHP and false are equivalent:

  • Boolean value FALSE

  • Integer value 0 (0)

  • Floating point value: 0.0 (0)

  • Empty string and string "0"

  • Array that does not contain any elements

  • Objects that do not include any member variables (applicable only to PHP 4.0)

  • Special Type NULL (including unassigned variables)

  • SimpleXML object generated from null tag

For example$a = 0,$b = 1, Then:

  • $a = $bYes 1 ,! 1 is false, so if (! $ A = $ B) is false

  • $a != $bYes 1! = 0 is obviously true

If (! $ A = $ B) is equivalent to if (! ($ A = $ B )).

By the way, which teacher taught you this writing?

A! = B
! A = B

An equal sign is being assigned a value.
Code style is very important

// A and B are strings, and the values of the two should be not equal. However, their corresponding boolean values are false $ a = '0'; $ B = ''; $! = $ B; // true! $ A = $ B; // false


The output result is as follows:

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.