B4P applies commonly practiced operator precedence rules when carrying out calculations with unary and binary operators. For example, multiplications and divisions are performed first before continuing with additions and subtractions.
| 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