How to use basic PHP operators

Source: Internet
Author: User
This article introduces the use and analysis of basic PHP operators. For more information, see 1. arithmetic operators: +,-, *,/, and %.

2. increment/decrease operators: for example, $ a ++, $ a --, ++ $ a, -- $.

For example:

$ A = 10;
$ B = 5;
$ C = $ a ++; // assign values first and then auto-increment. $ C = $ a, $ a = $ a + 1
$ D = $ B --; // assign values first, and then subtract from them. $ D = $ B, $ B = $ A-1
Echo '$ a ='. $ a. "|". '$ c ='. $ c .'
'; // $ A = 11, $ c = 10
Echo '$ B ='. $ B. "|". '$ d ='. $ d .'
'; // $ B = 4, $ d = 5
?>

$ A = 10;
$ B = 5;
$ C = ++ $ a; // auto-increment first, and then assign a value. $ A = $ a + 1, $ c = $
$ D = -- $ B; // first auto-subtract and then assign a value. $ B = $ A-1, $ d = $ B
Echo '$ a ='. $ a. "|". '$ c ='. $ c .'
'; // $ A = 11, $ c = 11
Echo '$ B ='. $ B. "|". '$ d ='. $ d .'
'; // $ B = 4, $ d = 4
?>

3. Comparison operator: Reference Document

4. logical operators:

For example:

$ A = 10; $ B = 7;
If ($ a ++> 8 | $ B ++> 7) {// $ a ++> 8 is true, $ B ++> 7 is not executed.
Echo 'OK! ';
}
Echo 'a = '. $ a.' B = '. $ B; // output OK, a = 11, B = 7

Change

$ A = 10; $ B = 7;
If ($ a ++> 10 & $ B ++> 7) {// $ a ++> 8 is false, $ B ++> 7 is not executed.
Echo 'OK! ';
}
Echo 'a = '. $ a.' B = '. $ B; // a = 11, B = 7

Details: and & all indicate logic and where are their differences?

Mainly reflected in priority

And priority and <= <& or <= <| for example:

$ A = false | true; // & >=> and; compare false first | true, and then assign a value.
$ B = false or true; // | |>=> or; first, assign $ B = false and then compare. Therefore, the result is false.
Var_dump ($ a, $ B); // bool (true) bool (false)

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.