PHP ?: ternary operator the Elvis operator


Warning: Undefined array key "socialize_RedditWidget" in /home/phpacd/websites/shkodenko.com/wp-content/plugins/socialize/frontend/socialize-services.php on line 166

You can use ?: ternary operator in PHP then you need not empty value. Set value to a $action variable from $_POST[‘action’] parameter if it is not empty or use string default instead. It is shown in the example code below:

// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

For more information see PHP documentation page for Ternary Operator.

In PHP 5.3, a shorter syntax for the ternary operator was introduced, which allows to leave out the middle part of the ternary operator for a quick shorthand evaluation. It is also called the Elvis operator sometimes because: