PHP logical operator.

Source: Internet
Author: User
There are two problems when judging the file type. The code is as follows:
if ($type!== ' gif ' | | $type!== ' JPEG ' | | $type!== ' png ') {
echo "Format error";
}
else {
Echo $type;
}
Question 1: Not equal, is with!==?
Issue 2: | | It doesn't work, or it's useless to change it. If only one can be judged, the explanation is not equal to the correct.
but | | Why not work, this if in C # but absolutely workable AH.


Reply to discussion (solution)

1 can be expressed in! =, can also be expressed with!==, the specific difference between the mother
2 you mean as long as the type is gif,jpeg,png to judge correctly?
That should be written like this: if ($type!== ' gif ' && $type!== ' jpeg ' && $type!== ' png ')

The!== operator is all equal to the negative usage of ' = = = ', which distinguishes values, data types, capitalization, etc.
Just change to this! =.

Question 1: Not equal, is with!==?
! = is not equal to
!== Not all equal to

Issue 2: | | It doesn't work, or it's useless to change it.
You need to use and && logic to judge.

Sorry, the logic is wrong. I'm sorry to delay your time.

Not equal to:<>,! =,!==
Where!== compare types before comparison

In your context, $type!== ' gif ' | | $type!== ' jpeg ' | | $type!== ' png ' is wrong
This logical expression indicates that the condition is true as long as the $type is not equal to one of GIF, JPEG, and PNG.
Set $type = ' gif ', then he must not be equal to JPEG, nor PNG
C # is also wrong, C # is created by the Martians?

So the expression should be the same as an expression, not an expression
$type!== ' gif ' && $type!== ' jpeg ' && $type!== ' png '

  • 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.