Last Updated: February 25, 2016
·
302
· pitje

Ternary operater in PHP5.3

according to php.net; "Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise."

So, in the following line, if there is set a $POST['test'], the variable will contain the value of $POST['test']. If there's no $_POST'test', $test will contain the boolean value FALSE.

$test = $_POST['test'] ?: false;

Not exactly rocketsurgery, but it saves a few keystrokes and (imho) looks 'cleaner'.