Operator Precedence In PHP

Share Now

The precedence of an operator specifies how “tightly” it binds two expressions together. For example, in the expression 1 + 5 * 3, the answer is 16 and not 18 because the multiplication (“*”) operator has higher precedence than the addition (“+”) operator.

***Parentheses may be used to force precedence, if necessary. For instance: (1 + 5) * 3 evaluates to 18.

$f = false || true; // true --> because (false || true) = true ... and  '||' has higher Precedence than '='
$t = false or true; // false --> because 'or' has lower Precedence that '='. so it basically assign false into  $t

var_dump($f,$t);
Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert