Skip to content

Instantly share code, notes, and snippets.

@shadda
Last active September 30, 2015 23:41
Show Gist options
  • Select an option

  • Save shadda/85941a45af7d42fbcb37 to your computer and use it in GitHub Desktop.

Select an option

Save shadda/85941a45af7d42fbcb37 to your computer and use it in GitHub Desktop.
<?php
function coalesce(&$value, $ifnull=null)
{
if(!isset($value))
{
return $ifnull;
}
return $value;
}
//Usage
$myVar = coalesce($_GET['some key that may or may not exist']); //By default, $myVar is set to null if $_GET[...] isn't set
$someOtherVarWithADefaull = coalesce($_GET['do I have chilli?'], true); //If it doesn't exist, it returns true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment