Last active
September 30, 2015 23:41
-
-
Save shadda/85941a45af7d42fbcb37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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