Php operator priority

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise logical operators php operator php tutorial

Php Tutorial operator priority:
Calculate multiplication, division, and addition and subtraction. When brackets are encountered, calculate the values in brackets.
The operator priority specifies how closely two expressions are bound ". For example, the result of expression 1 + 5*3 is 16 instead of 18 because the priority of the multiplication sign ("*") is higher than that of the plus sign ("+. If necessary, use parentheses to forcibly change the priority. Example: (1 + 5) the value of * 3 is 18. If the operator priority is the same, the left join order from left to right is used.
  
Operator priority combined with additional operator information
Not combined with clone new clone and new
Left [array ()
Non-union ++ -- increment/decrease operator
Not Associated ~ -(Int) (float) (string) (array) (object) (bool) @ Type
Uncombined instanceof type
Right join! Logical operators
Left */% arithmetic operator
Left +-. Arithmetic operators and string operators
Left <> bitwise operator
Non-union <<=>=<> comparison operator
Not combined =! ===! = Comparison operator
Left & bit operators and references
Left ^ bit operator
Left | bitwise operator
Left & logical operators
Left | logical operator
Left? : Ternary operator
Right = + =-= * =/=. = % = & =|=^= <<=>> = value assignment operator
Left and logical operators
Left xor logical operator
Left or logical operators
Left, used in multiple places


Example name result
-$ A: returns the negative value of $.
$ A + $ B addition: sum of $ a and $ B.
The difference between $ a-$ B subtraction $ a and $ B.
The product of $ a * $ B multiplication $ a and $ B.
$ A/$ B Division $ a divided by the operator of $ B.
$ A % $ B modulo $ a divided by the remainder of $ B.

<? Php
$ A = 10;
$ B = 20;
Echo-$ a; // returns the negative value of $. -10
Echo "<br/> ";

Echo $ a + $ B; // add the sum of $ a and $ B. 30
Echo "<br/> ";

Echo $ a-$ B; // subtraction between $ a and $ B. -10
Echo "<br/> ";

Echo $ a * $ B; // multiply the product of $ a and $ B. 200
Echo "<br/> ";

Echo $ a/$ B; // Division $ a divided by the operator of $ B. 0.5
Echo "<br/> ";

Echo $ a % $ B; // modulus $ a divided by the remainder of $ B. 10
Echo "<br/> ";
?>

<? Php
$ A = 3*3% 5; // (3*3) % 5 = 4
$ A = true? 0: true? 1: 2; // (true? 0: true )? 1: 2 = 2

$ A = 1;
$ B = 2;
$ A = $ B + = 3; // $ a = ($ B + = 3)-> $ a = 5, $ B = 5
?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.