Home  >  Article  >  Backend Development  >  If there are parentheses in PHP operation, should the parentheses be calculated first?

If there are parentheses in PHP operation, should the parentheses be calculated first?

(*-*)浩
(*-*)浩Original
2019-10-08 11:20:142794browse

Operator precedence specifies how "tightly" two expressions are bound. For example, the expression 1 5 * 3 evaluates to 16 instead of 18 because the multiplication sign ("*") has higher precedence than the plus sign (" "). Parentheses can be used to force a priority change if necessary. For example: (1 5) * 3 has the value 18.

If there are parentheses in PHP operation, should the parentheses be calculated first?

If the operators have the same precedence, the combination direction of the operators determines how to operate. For example, "-" is left-joint, then 1 - 2 - 3 is equivalent to (1 - 2) - 3 and the result is -4. On the other hand, "=" is right-joint, so $a = $b = $c is equivalent to $a = ($b = $c). (Recommended learning: PHP Video Tutorial)

Operators with the same priority that are not combined cannot be used together. For example, 1 1 is illegal in PHP. But on the other hand the expression 1

The use of brackets, even when it is not necessary, clearly indicates the order of operations through the pairing of brackets, rather than relying on operator priority and associativity. This can usually increase the code's readability. Readability.

The following table lists the operators in order of precedence from high to low. Operators in the same line have the same precedence, and the direction in which they are combined determines the order of evaluation.

If there are parentheses in PHP operation, should the parentheses be calculated first?

The above is the detailed content of If there are parentheses in PHP operation, should the parentheses be calculated first?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn