Skip to content

Instantly share code, notes, and snippets.

@thewebguy
Created August 27, 2012 20:56
Show Gist options
  • Save thewebguy/3492147 to your computer and use it in GitHub Desktop.
Save thewebguy/3492147 to your computer and use it in GitHub Desktop.
Function to get the first item that's set. I always find myself writing crap like this out a dozen times.
<?
/*
$first = null;
$second = 'ketchup';
$third = 'mustard';
$condiment = whichever($first, $second, $third); // $condiment == 'ketchup';
*/
function whichever() {
$options = func_get_args();
foreach ($options as $option) {
if (isset($option) && $option) {
return $option;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment