Php & logic and operator usage-PHP source code

Source: Internet
Author: User
If the previous result is false, the operation is not executed. if the result is true, continue with the following operations. If the previous result is false, the operation is not executed. if the result is true, continue with the following operations.

Example:
! Defined ('Magic _ QUOTES_GPC ') & define ('Magic _ QUOTES_GPC', get_magic_quotes_gpc ());

O (zookeeper) o Alas, I was dizzy. today I asked N more people. Finally, I figured out what was going on "&".

The operator does not determine what it means. well, if the previous operator is false. The subsequent statements are not executed. So that we do not have to write if

This is simple...

// Simple description: if the previous judgment is false, the operation is not executed. if the judgment is true, the following definition constant operation is continued.

Logical operators
Example Name Result
$ A and $ B And (logical And) TRUEIf both $ a and $ B areTRUE.
$ A or $ B Or (logical Or) TRUEIf either $ a or $ B isTRUE.
$ A xor $ B Xor (logical exclusive or) TRUEIf either $ a or $ B isTRUEBut not at the same time.
! $ Not (logical non) TRUEIf $ a is notTRUE.
$ A & $ B And (logical And) TRUEIf both $ a and $ B areTRUE.
$ A | $ B Or (logical Or) TRUEIf either $ a or $ B isTRUE.


Example #1 Example of logical operators

The code is as follows:

 


The output in the above example is similar:
Bool (true)
Bool (false)
Bool (false)
Bool (true)

Another example that might help.

(Isset ($ panelemail )&&! Empty ($ panelemail )? $ Panelemail: $ userdata ['email ']);
?>
Returns the userdata email address, but this

(Isset ($ panelemail) AND! Empty ($ panelemail )? $ Panelemail: $ userdata ['email ']);
?>
Returns false.

The reason is that the two types of ands have a different order of precedence. "&" is higher than "AND", and "? : "Operator just happens to come between the two. also, since "|" (or) is actually higher than "AND," you shoshould never mix & s and | s with ANDs and ORs without paretheses.

For example:

True & false | false
?>
Returns false,

True AND false | false
?>
Returns true.

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.