PHP – Operator Precedence

0 0
Read Time:1 Minute, 34 Second

Operator Precedence

You Can force precedence using parentheses otherwise they are evaluated in this order:

XOR – exclusive or-either a or b is true but not both.

AND is not the same like &&

For Example:

<?php 
echo $a && $b || $c; 
?>

is not the same like

<?php 
echo $a AND $b || $c; 
?>

the first thing is
(a and b) or c

the second
a and (b or c)

because || has got a higher priority than and, but less than &&

Operators:

Operator are used to perform operation.

Operator are mainly divided by three groups.

  1. Unary Operators that takes one values
  2. Binary Operators that takes two values
  3. Ternary operators that takes three values

Operator are mainly divided by three groups that are totally seventeen types.

1. Arithmetic Operator

+ Addition
– Subtraction
* Multiplication
/ Division
% Modulo
** Exponentiation

2. Assignment Operator

= equal

3. Array Operator

+ Union
    == Equality
    === Identity
    != Inequality
    <> Inequality
    !==     Non-identity

4. Bit-wise Operator

& and
^ xor
| not

5. Comparison Operator

==  equal to
=== identical
!=  not equal
!== not identical
<>  not equal
< less than
<= less than or equal
> greater than
>= greater than or equal
<=> spaceship operator

6. Execution Operator

“ back-ticks

7. Execution Operator

@ at the rate sign

8. Incrementing/Decrementing Operator

++$a Pre-Increment
$a++ Post-Increment
– -$a Pre-Decrement
$a- – Post-Decrement

9. Logical Operator

&& And
    || Or
    ! Not
   and And
    xor Xor
    or Or

10. String Operator

. concatenation operator
  .= concatenating assignment operator

11. Type Operator

instanceof instanceof

12. Ternary or Conditional operator

?: Ternary operator

13. Null Coalescing Operator

??” null coalescing

14. Clone new Operator

clone new clone new

15. yield from Operator

yield from yield from

16. yield Operator

yield yield

17. print Operator

print print

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Comment