Created
December 14, 2012 19:48
-
-
Save mertenvg/4288086 to your computer and use it in GitHub Desktop.
Extract an option from the results of getopt specifying the keys in order of preference.
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
/** | |
* Extract an option from the results of getopt specifying the | |
* keys in order of preference. | |
* | |
* @param array $options Result from getopt('ab:c::', array('add', 'bacon', 'create')) | |
* @param string $key1 First key to look for e.g. 'add' | |
* @param string $key2 Second key to look for e.g. 'a' | |
* @param string $keyn Other possible aliases... | |
* @return mixed The value from options array or null otherwise | |
*/ | |
function optval(array &$options, $key1, $key2, $keyn = null) | |
{ | |
$args = func_get_args(); | |
$options = array_shift($args); | |
foreach ($args as $key) { | |
if (isset($options[$key])) { | |
return $options[$key]; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment