Created
May 27, 2009 21:48
-
-
Save Oshuma/118931 to your computer and use it in GitHub Desktop.
value_or_default()
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 | |
| // Reason #5,671 PHP sucks balls: Can't set default array values | |
| // (default return values for non-existing keys). | |
| // Returns the $key's value from $array if it exists; otherwise return $default. | |
| function value_or_default($array, $key, $default = '') { | |
| return array_key_exists($key, $array) ? $array[$key] : $default; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment