fork download
  1. <?php
  2. $search = array(1, 2, 0, 4);
  3.  
  4. $callback = function($number) {
  5. return ($number == 0);
  6. };
  7.  
  8. function searchByCallback($array, callable $c) {
  9. $filter = array();
  10.  
  11. foreach($array as $value) {
  12. if ($c($value)) {
  13. $filter[] = $value;
  14. }
  15. }
  16.  
  17. return $filter;
  18. }
  19.  
  20. $searched = searchByCallback($search, $callback);
  21.  
  22. print_r($searched);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 0
)