Skip to content

Instantly share code, notes, and snippets.

@nhalstead
Last active January 31, 2018 22:35
Show Gist options
  • Save nhalstead/1f23acaebf86d73493de55d005483535 to your computer and use it in GitHub Desktop.
Save nhalstead/1f23acaebf86d73493de55d005483535 to your computer and use it in GitHub Desktop.
<?php
/**
* Function Switch
* Call the Funciton acording to the True or False Value.
* If any more Paramiters are passed after the first 3
* they are passed as paramiters for the called funciton.
*
* @param boolean The Selection of the Funciton to execute.
* @param Callable If the Boolean is True.
* @param Callable If the Boolean is False.
*/
function _q($switch, callable $if_true, callable $if_false){
$input = func_get_args();
unset($input[0], $input[1], $input[2]);
if($switch == true) {
return call_user_func_array($if_true, $input);
}
else if($switch == false) {
return call_user_func_array($if_false, $input);
}
}
// _q(true, function(){}, function(){});
_q(false,
function($e = 1){
// The True Statment
echo $e+10;
},
function($e = 0){
// The False Statment
echo $e-10;
},
1111
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment