fork download
  1. <?php
  2.  
  3. namespace detail;
  4.  
  5. function applyForEach($f, $t, $sequence)
  6. {
  7. foreach($sequence as $i) {
  8. call_user_func_array($f, array($i, $t[$i]));
  9. }
  10. }
  11.  
  12.  
  13. function applyForEach2($tuple, $_function)
  14. {
  15. $Indexes = range(0, count($tuple) - 1);
  16. \detail\applyForEach($_function, $tuple, $Indexes);
  17. }
  18.  
  19. /* test */
  20.  
  21. applyForEach2(array(1, 1, 2, 3, 5, 8, 13, 21), function($x, $y) {echo $x . ' => ' . $y . PHP_EOL;});
  22.  
Success #stdin #stdout 0.02s 24544KB
stdin
Standard input is empty
stdout
0 => 1
1 => 1
2 => 2
3 => 3
4 => 5
5 => 8
6 => 13
7 => 21