Created
May 18, 2017 05:26
-
-
Save m3m0r7/43adfea2d8af752e6f599151e366b023 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 | |
// all | |
function all (array $array, $initialize = true) { | |
return array_reduce($array, function ($carry, $item) { | |
return (bool) ($carry & $item); | |
}, $initialize); | |
} | |
function any (array $array, $initialize = false) { | |
return array_reduce($array, function ($carry, $item) { | |
return (bool) ($carry | $item); | |
}, $initialize); | |
} | |
// true | |
var_dump(all([true, true, true, true])); | |
// false | |
var_dump(all([true, true, true, false])); | |
// true | |
var_dump(any([true, false])); | |
// true | |
var_dump(any([true, true])); | |
// false | |
var_dump(any([false, false])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment