Similarities and differences between and between php logical operators

Source: Internet
Author: User
Similarities and differences between & amp; and & amp; in php logical operators: php has five arithmetic operators (& #43;-* %), with 6 operators assigned & #20540; operator (& amp; #43;-* % .), 8 Comparison operators (& lt; & gt ;! & Lt; & gt ;!), 6 logical operators (such as & amp;, |, & amp;, and php logical operators & and &)


Php has five arithmetic operators (+-*/%) and six value assignment operators (+ =-= * =/= % =. =), 8 comparison operators (==<><=>=! = <>! =), 6 types of logical operators (such as &, ||, &, | ,! . Here, the logic and & can be written as and, the logic or | can be written as or, and some other operators (error control operator @, execution operator anti-quotation marks "-- not single quotation marks, string operators. and. =, increment/decrease operator + +/--, three element operator? :).

For more information about operator priority, see related documents.


Similarities and differences between & and & in php

 4 & (++ $ a> 10) {}// the output result is 11. echo $ a;?>
 4 and (++ $ a> 10) {}// the output result is 11. echo $ a;?> **************************************** **********************
 4 & (++ $ a <10) {}// the output result is 11. echo $ a;?>
 4 & (++ $ a <10) {}// the output result is 11. echo $ a;?> **************************************** *****************
 10) {}// the output result is 10. echo $ a;?>
 10) {}// the output result is 11. echo $ a;?> **************************************** ***************************
 
 **************************************** ***************************
 


Expression 1 $ a & $ B, expression 2 $ a & $ B

1. similarities: both expressions are true when both $ a and $ B are true. The two operators have no effect on the expression results.

2. Differences: if $ a in expression $ a & $ B and $ a before expression is false, the determined expression is false, in this case, the logical operator & $ B after is no longer computed, that is, the so-called operator "short circuit. For the expression $ a & $ B, the $ B after the expression is still calculated regardless of the true or false $ a before the expression. Whether $ B after the logical operator is run may affect subsequent data and program results.

For logical operators | and |, the similarities and differences are the same as above.



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.