Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. /**
  3. * ArrayUtils
  4. *
  5. * @author Dustin Breuer <developer@thedust.in>
  6. * @license 2015 MIT
  7. */
  8.  
  9. namespace TheDusti\Util;
  10.  
  11. /**
  12. * Class ArrayUtils
  13. *
  14. * @package TheDusti\Util
  15. * @author Dustin Breuer <developer@thedust.in>
  16. */
  17. abstract class ArrayUtils {
  18.  
  19. /**
  20. * Test whether some Elements are <i>TRUE</i>
  21. *
  22. * @param array $aArr
  23. * @param callable $cTestFunc
  24. *
  25. * @return bool
  26. */
  27. public static function some(array $aArr, callable $cTestFunc = null){
  28. if($cTestFunc !== null){
  29. $aArr = array_map($cTestFunc, $aArr);
  30. }
  31.  
  32. foreach($aArr as $mElement){
  33. if($mElement){
  34. return true;
  35. }
  36. }
  37.  
  38. return false;
  39. }
  40.  
  41. /**
  42. * Test whether all Elements are <i>TRUE</i>
  43. *
  44. * @param array $aArr
  45. * @param callable $cTestFunc
  46. *
  47. * @return bool
  48. */
  49. public static function every(array $aArr, callable $cTestFunc = null){
  50. if($cTestFunc !== null){
  51. $aArr = array_map($cTestFunc, $aArr);
  52. }
  53.  
  54. foreach($aArr as $mElement){
  55. if(!$mElement){
  56. return false;
  57. }
  58. }
  59.  
  60. return true;
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement