- print_r: documentation ( source)
- iterator_to_array: documentation ( source)
<?php
function gen_map($f, $iter) {
foreach ($iter as $k => $v) {
yield $k => $f($v);
}
}
// example:
function times_two($x) {
return $x * 2;
}
$source = new ArrayIterator([0, 1, 2, 3, 4, 5, 6]);
//var_dump(iterator_to_array(iter_map('times_two', $source)));
print_r(iterator_to_array(gen_map('times_two', $source)));