PHP logical operators.

Source: Internet
Author: User
PHP logical operators. There are two problems when determining 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 to, yes! =?
Question 2: | it does not work. it is useless to change to or. If you only judge one, it means that it is not correct.
But | why does it not work? if it is in C #, it works absolutely.


Reply to discussion (solution)

1 can be used! = Indicates, you can also use! = Indicates the difference
2. do you mean that if the type is gif, jpeg, or png, the image is correct?
It should be written as follows: if ($ type! = 'GIF' & $ type! = 'Jpeg '& $ type! = 'PNG ')

! = The operator is all equal to '=' in a negative usage. This requires a score, data type, case sensitivity, etc.
Change to this! =.

Question 1: not equal to, yes! =?
! = Is not equal
! = Not all equal

Question 2: | it does not work. it is useless to change to or.
You need to use and & for logical judgment.

Sorry, the logic is incorrect. Sorry for your delay.

Not equal to: <> ,! = ,! =
Here! = Comparison type first

In your context, $ type! = 'GIF' | $ type! = 'Jpeg '| $ type! = 'PNG 'is incorrect
This logical expression indicates that the condition is true if $ type is not equal to one of gif, jpeg, and png.
If $ type = 'gifs 'is set, it must not be jpeg or png.
C # is not true. C # Is it created by a Martian?

Therefore, the expression should be an expression rather than an or 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.