fork(1) download
  1. <?php
  2.  
  3. class Item {
  4. private $data;
  5. public function __construct ($value) {$this->data = $value;}
  6. public function __toString() {return strval($this->data);}
  7. public function isValid() {return $this->data != 666;}
  8. }
  9.  
  10. function foreach_with_fitler($array, $iterator, $body, $fitler) {
  11. @array_walk(array_filter($array, $fitler), function($item, $key)use($iterator, $body){
  12. $$iterator = $key;
  13. eval($body);
  14. });
  15. }
  16.  
  17. $items = array(new Item(13), new Item(265), new Item(666), new Item(1488));
  18.  
  19. define('FITLER', 'FITLER');
  20.  
  21. function FITLER($value) {return $value->isValid();}
  22.  
  23. foreach_with_fitler($items, '$item', 'echo $item . PHP_EOL;', FITLER);
  24.  
Success #stdin #stdout 0.02s 24620KB
stdin
Standard input is empty
stdout
13
265
1488