Skip to content

Instantly share code, notes, and snippets.

@killercup
Last active June 2, 2016 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killercup/6c283d779d7a71538ae1c419dc34932a to your computer and use it in GitHub Desktop.
Save killercup/6c283d779d7a71538ae1c419dc34932a to your computer and use it in GitHub Desktop.
<?php
/**
* Wutcol
*
* Does what `$array[$key] || $alternative` does in JS.
*
* The name was chosen because this is how you pronounce `?:` according to the
* [Hoon language documentation][1]. Also, it's quite unlikely to conflict with
* any other global PHP function.
*
* [1]: https://gist.github.com/killercup/be14570af13cbddb5dbc
*
* @param array $array
* @param any $key
* @param any $alternative
* @return any
*/
function wutcol(array $array, $key, $alternative) {
if (array_key_exists($key, $array) && !empty($array[$key])) {
return $array[$key];
} else {
return $alternative;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment