PHP operator examples including arithmetic, assignment, comparison, increment/decrement, logical, and string operators.
$y); // returns false because values are equal
?>
$y); // returns true because $x is greater than $y
?>
= $y); // returns true because $x is greater than or equal to $y
?>
$y); // returns -1 because $x is less than $y
echo "
";
$x = 10;
$y = 10;
echo ($x <=> $y); // returns 0 because values are equal
echo "
";
$x = 15;
$y = 10;
echo ($x <=> $y); // returns +1 because $x is greater than $y
?>
"red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
print_r($x + $y); // union of $x and $y
?>
"red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x == $y);
?>
"red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x === $y);
?>
"red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x <> $y);
?>
"red", "b" => "green");
$y = array("c" => "blue", "d" => "yellow");
var_dump($x !== $y);
?>
");
$user = "John Doe";
// if empty($user) = FALSE, set $status = "logged in"
echo $status = (empty($user)) ? "anonymous" : "logged in";
?>
");
// variable $color is "red" if $color does not exist or is null
echo $color = $color ?? "red";
?>