How to use basic PHP operators _ PHP Tutorial

Source: Internet
Author: User
PHP-based operators. 1. arithmetic operators: +,-, *, and %. 2. increment/decrease operators: for example, $ a ++, $ a --, ++ $ a, -- $ a. For example :? Php $ a10; $ b5; $ c $ a ++; assign a value first and then auto-increment. $ C $ a, $ a + 1 $ d $ B --; 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 them from each other. $ 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 = ++ $;// Auto-increment first and then assign a value. $ A = $ a + 1, $ c = $
$ D = -- $ B;// First 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 represent 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, so the result is false.
Var_dump ($ a, $ B );//Bool (true) bool (false)

Bytes. 2. increment/decrease operators: for example, $ a ++, $ a --, ++ $ a, -- $ a. For example :? Php $ a = 10; $ B = 5; $ c = $ a ++; // assign values first and then auto-increment. $ C = $ a, $ a = $ a + 1 $ d = $ B --;...

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.