Setting default values (conditional assignment) Setting default values (conditional assignment) ruby ruby

Setting default values (conditional assignment)


As of PHP 5.3 you can use the ternary operator while omitting the middle argument:

$x = $x ?: 'default';


As of PHP 7.0, you can also use the null coalesce operator

// PHP version < 7.0, using a standard ternary$x = (isset($_GET['y'])) ? $_GET['y'] : 'not set';// PHP version >= 7.0$x = $_GET['y'] ?? 'not set';