Last active
June 2, 2016 18:17
-
-
Save killercup/6c283d779d7a71538ae1c419dc34932a to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* 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