Skip to content

Instantly share code, notes, and snippets.

@Oshuma
Created May 27, 2009 21:48
Show Gist options
  • Select an option

  • Save Oshuma/118931 to your computer and use it in GitHub Desktop.

Select an option

Save Oshuma/118931 to your computer and use it in GitHub Desktop.
value_or_default()
<?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