Ternary Operator in PHP
The ternary operator is similar to an if/else statement. Here is an example for if/else statement:
if (empty($_POST[’submit’])) {
$action = ‘default’;
} else {
$action = $_POST[’submit’];
}
We can use the above example with ternary operator which will produce the same result using less space. It makes use of ? and : just like if and else.
$action = (empty($_POST[’submit’])) ? ‘default’ : $_POST[’submit’];
