Skip to content

Instantly share code, notes, and snippets.

@salathe
Created July 8, 2011 11:11
Show Gist options
  • Save salathe/1071613 to your computer and use it in GitHub Desktop.
Save salathe/1071613 to your computer and use it in GitHub Desktop.
Iterator Map
<?php
function iterator_map($iterator, $callback)
{
$result = array();
foreach ($iterator as $key => $current) {
$result[$key] = $callback($current, $key, $iterator);
}
return $result;
}
$files = new LimitIterator(new FilesystemIterator(__DIR__), 0, 10);
$mapped = iterator_map($files, function($c){ return $c->getSize(); });
var_dump($mapped);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment