Introduction to PHP Operator precedence

Source: Internet
Author: User
Tags bitwise operators php operator

The operator precedence specifies how tightly the two expressions are bound. For example, the result of the expression 1 + 5 * 3 is that It is because multiplication sign ("*") has a higher priority than the plus sign ("+"). You can use parentheses to force a change of precedence if necessary. For example:(1 + 5) * 3 is the value of . If the operator has the same precedence, the left-to-right leftist order is used.

The following table lists the precedence of operators from high to low. Operators in the same row have the same precedence, at which point their binding direction determines the order of evaluation.

Operator Precedence
Combination Direction operator Additional Information
Non-binding Clone new Clone and new
Left [ Array ()
Non-binding ++ -- Increment/decrement operator
Non-binding ~-(int) (float) (string) (array) (object) (BOOL) @ Type
Non-binding instanceof Type
Right combination ! logical operators
Left * / % Arithmetic operators
Left + - . Arithmetic operators and string operators
Left << >> Bitwise operators
Non-binding < <= > >= <> Comparison operators
Non-binding == != === !== Comparison operators
Left & Bitwise operators and references
Left ^ Bitwise operators
Left | Bitwise operators
Left && logical operators
Left || logical operators
Left ? : Ternary operators
Right = + = = *=/=. =%= &= |= ^= <<= >>= Assignment operators
Left and logical operators
Left Xor logical operators
Left Or logical operators
Left , Used in many places

Leftist indicates that the expression is evaluated from left to right and vice versa.

Example #1 Combination Direction

<?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?> use parentheses to enhance the readability of your code.

Note:

Although = is lower than most other operators, PHP still allows an expression similar to the following:if (! $a = foo ()), in this case foo () The return value is assigned to the $a .

Http://www.docin.com/p1-1560374424.html

Http://www.docin.com/p1-1560374424.html

Introduction to PHP Operator precedence

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.