Arithmetic operator: Addition (+)

                
                    <?php
                    $x = 10;  
                    $y = 6;
                    
                    echo $x + $y;
                    ?>  
                
                

Arithmetic operator: Subtraction (-)

                
                    <?php
                    $x = 10;  
                    $y = 6;
                    
                    echo $x - $y;
                    ?> 
                
                

Arithmetic operator: Multiplication (*)

                
                    <?php
                    $x = 10;  
                    $y = 6;
                    
                    echo $x * $y;
                    ?>
                
                

Arithmetic operator: Division (/)

                
                    <?php
                    $x = 10;  
                    $y = 6;
                    
                    echo $x / $y;
                    ?>
                
                

Arithmetic operator: Modulus (%)

                
                    <?php
                    $x = 10;  
                    $y = 6;
                    
                    echo $x % $y;
                    ?>
                
                

Assignment operator: x = y

                
                    <?php
                    $x = 10;  
                    echo $x;
                    ?>
                
                

Assignment operator: x += y

                
                    <?php
                    $x = 20;  
                    $x += 100;
                    
                    echo $x;
                    ?> 
                
                

Assignment operator: x -= y

                
                    <?php
                    $x = 50;
                    $x -= 30;
                    
                    echo $x;
                    ?>  
                
                

Assignment operator: x *= y

                
                    <?php
                    $x = 5;
                    $x *= 6;
                    
                    echo $x;
                    ?> 
                
                

Assignment operator: x /= y

                
                    <?php
                    $x = 10;
                    $x /= 5;
                    
                    echo $x;
                    ?> 
                
                

Assignment operator: x %= y

                
                    <?php
                    $x = 15;
                    $x %= 4;
                    
                    echo $x;
                    ?>
                
                

Comparison operator: Equal (==)

                
                    <?php
                    $x = 100;  
                    $y = "100";
                    
                    var_dump($x == $y); // returns true because values are equal
                    ?>
                
                

Comparison operator: Identical (===)

                
                    <?php
                    $x = 100;  
                    $y = "100";
                    
                    var_dump($x === $y); // returns false because types are not equal
                    ?>
                
                

Comparison operator: Not equal (!=)

                
                    <?php
                    $x = 100;  
                    $y = "100";
                    
                    var_dump($x != $y); // returns false because values are equal
                    ?>
                
                

Comparison operator: Not equal (<>)

                
                    <?php
                    $x = 100;  
                    $y = "100";
                    
                    var_dump($x <> $y); // returns false because values are equal
                    ?>
                
                

Comparison operator: Not identical (!==)

                
                    <?php
                    $x = 100;  
                    $y = "100";
                    
                    var_dump($x !== $y); // returns true because types are not equal
                    ?> 
                
                

Comparison operator: Greater than (>)

                
                    <?php
                    $x = 100;
                    $y = 50;
                    
                    var_dump($x > $y); // returns true because $x is greater than $y
                    ?>
                
                

Comparison operator: Less than (<)

                
                    <?php
                    $x = 10;
                    $y = 50;
                    
                    var_dump($x < $y); // returns true because $x is less than $y
                    ?>
                
                

Comparison operator: Greater than or equal (>=)

                
                    <?php
                    $x = 50;
                    $y = 50;
                    
                    var_dump($x >= $y); // returns true because $x is greater than or equal to $y
                    ?>
                
                

Comparison operator: Less than or equal (<=)

                
                    <?php
                    $x = 50;
                    $y = 50;
                    
                    var_dump($x <= $y); // returns true because $x is less than or equal to $y
                    ?>
                
                

Comparison operator: Spaceship (<=>)

                
                    <?php
                    $x = 5;  
                    $y = 10;
                    
                    echo ($x <=> $y); // returns -1 because $x is less than $y
                    echo "<br>";
                    
                    $x = 10;  
                    $y = 10;
                    
                    echo ($x <=> $y); // returns 0 because values are equal
                    echo "<br>";
                    
                    $x = 15;  
                    $y = 10;
                    
                    echo ($x <=> $y); // returns +1 because $x is greater than $y
                    ?>
                
                

Increment operator: ++$x

                
                    <?php
                    $x = 10;  
                    echo ++$x;
                    ?>
                
                

Increment operator: $x++

                
                    <?php
                    $x = 10;  
                    echo $x++;
                    ?>
                
                

Decrement operator: --$x

                
                    <?php
                    $x = 10;  
                    echo --$x;
                    ?>
                
                

Decrement operator: $x--

                
                    <?php
                    $x = 10;  
                    echo $x--;
                    ?>
                
                

Logical operator: and

                
                    <?php
                    $x = 100;  
                    $y = 50;
                    
                    if ($x == 100 and $y == 50) {
                        echo "Hello world!";
                    }
                    ?>
                
                

Logical operator: or

                
                    <?php
                    $x = 100;  
                    $y = 50;
                    
                    if ($x == 100 or $y == 80) {
                        echo "Hello world!";
                    }
                    ?>
                
                

Logical operator: xor

                
                    <?php
                    $x = 100;  
                    $y = 50;
                    
                    if ($x == 100 xor $y == 80) {
                        echo "Hello world!";
                    }
                    ?>
                
                

Logical operator: && (and)

                
                    <?php
                    $x = 100;  
                    $y = 50;
                    
                    if ($x == 100 && $y == 50) {
                        echo "Hello world!";
                    }
                    ?> 
                
                

Logical operator: || (or)

                
                    <?php
                    $x = 100;  
                    $y = 50;
                    
                    if ($x == 100 || $y == 80) {
                        echo "Hello world!";
                    }
                    ?>
                
                

Logical operator: not

                
                    <?php
                    $x = 100;  
                    
                    if ($x !== 90) {
                        echo "Hello world!";
                    }
                    ?>
                
                

String operator: Concatenation of $txt1 and $txt2

                
                    <?php
                    $txt1 = "Hello";
                    $txt2 = " world!";
                    echo $txt1 . $txt2;
                    ?> 
                
                

Array operator: Union (+)

                
                    <?php
                    $txt1 = "Hello";
                    $txt2 = " world!";
                    $txt1 .= $txt2;
                    echo $txt1;
                    ?>
                
                

Array operator: Equality (==)

                
                    <?php
                    $x = array("a" => "red", "b" => "green");  
                    $y = array("c" => "blue", "d" => "yellow");  
                    
                    print_r($x + $y); // union of $x and $y
                    ?> 
                
                

Array operator: Identity (===)

                
                    <?php
                    $x = array("a" => "red", "b" => "green");  
                    $y = array("c" => "blue", "d" => "yellow");  
                    
                    var_dump($x == $y);
                    ?>
                
                

Array operator: Inequality (!=)

                
                    <?php
                    $x = array("a" => "red", "b" => "green");  
                    $y = array("c" => "blue", "d" => "yellow");  
                    
                    var_dump($x === $y);
                    ?> 
                
                

Array operator: Inequality (<>)

                
                    <?php
                    $x = array("a" => "red", "b" => "green");  
                    $y = array("c" => "blue", "d" => "yellow");  
                    
                    var_dump($x <> $y);
                    ?>
                
                

Array operator: Non-identity (!==)

                
                    <?php
                    $x = array("a" => "red", "b" => "green");  
                    $y = array("c" => "blue", "d" => "yellow");  
                    
                    var_dump($x !== $y);
                    ?> 
                
                

Conditional assignment operator: Ternary (?:)

                
                    <?php
                    // if empty($user) = TRUE, set $status = "anonymous"
                    echo $status = (empty($user)) ? "anonymous" : "logged in";
                    echo("<br>");
                 
                    $user = "John Doe";
                    // if empty($user) = FALSE, set $status = "logged in"
                    echo $status = (empty($user)) ? "anonymous" : "logged in";
                 ?>  
                
                

Conditional assignment: Null coalescing (??)

                
                    <?php
                    // variable $user is the value of $_GET['user']
                    // and 'anonymous' if it does not exist
                    echo $user = $_GET["user"] ?? "anonymous";
                    echo("<br>");
                   
                    // variable $color is "red" if $color does not exist or is null
                    echo $color = $color ?? "red";
                 ?>