Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Created June 21, 2011 13:51
Show Gist options
  • Save rowanmanning/1037891 to your computer and use it in GitHub Desktop.
Save rowanmanning/1037891 to your computer and use it in GitHub Desktop.
PHP 5.3's shortened ternary operator
<?php
function hello($arg = 'World') {
// sanitize arguments
$arg = $arg ?: 'World';
// return message
return "Hello {$arg}!";
}
print hello('You'); // outputs 'Hello You!'
print hello(); // outputs 'Hello world!'
print hello(null); // outputs 'Hello world!'
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment