Shorthand operator in PHP
In this example, if the value of $a is greater than 15, then 20 will be returned and will be assigned to $b, else 5 will be returned and assigned to $b.
<?php
$a = 10;
$b = $a > 15 ? 20 : 5;
print ("Value of b is " . $b);
?>
Output
Value of b is 5
In this example, if the value of $age is more than or equal to 18, “Adult” is passed to print function and printed, else “Not Adult” is passed and printed.
<?php
$age = 20;
print ($age >= 18) ? "Adult" : "Not Adult";
?>
Adult