B4P applies meaningful operator precedence rules when carrying out calculations with unary and binary operators. For calculation examples, do the multiplications and divisions first, and then the additions and subtractions (briefly said in German: Punktrechnung vor Strichrechnung). Use parentheses to influence the precedence rules.
Precedence | Symbols | Description |
---|---|---|
1 (highest) | +, -, ~, ! | All unary operators |
2 | *, / | Arithmetic operators: multiplication and division |
3 | +, - | Arithmetic operators: addition and subtraction |
4 | =, ==, <>, !=, >, >, <, <= | Comparison operators |
5 (lowest) | &, | | Logical operators |
The operators are described in the following section.
Parentheses can be used to overrule the operator precdences.
echo( 3 + 10 *2 + 100*4 ); // 423
echo( (3 + 10)*2 + 100*4 ); // 426
echo( 3 + 2 >= 2 + 2 ); // True
echo( 3 + (2 >= 2) + 2 ); // 6 (True in middle converts to 1)
423
426
true
6