Last active
December 31, 2018 01:41
-
-
Save nathan-fiscaletti/77cbc3952de72d0248c60e2422905d44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if (! function_exists('_or')) { | |
/** | |
* Shorthand OR comparison. | |
* | |
* @param mixed $compareTo | |
* @param mixed $values | |
*/ | |
function _or(...$values) { | |
$result = false; | |
$compareTo = array_shift($values); | |
foreach($values as $value) { | |
$result = ($result || ($value == $compareTo)); | |
if ($result) | |
break; | |
} | |
return $result; | |
} | |
} | |
if (! function_exists('_sor')) { | |
/** | |
* Strict shorthand OR comparison. | |
* | |
* @param mixed $compareTo | |
* @param mixed $values | |
*/ | |
function _sor(...$values) { | |
$result = false; | |
$compareTo = array_shift($values); | |
foreach($values as $value) { | |
$result = ($result || ($value === $compareTo)); | |
if ($result) | |
break; | |
} | |
return $result; | |
} | |
} | |
$a = 'foo'; | |
if (_or($a, null, 'sex')) { | |
echo 'A is null or sex'; | |
} else { | |
echo 'A is not null or sex'; | |
} | |
// -- or -- | |
echo 'A is' . ((_sor($a, null, 'sex')) ? '' : ' not') . ' null or sex.'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment