I wonder which of the two is faster? A closure with use() or a function with parameter passing?
$mapping = [...] // array with many key, value pairs
function myFn($item, $mapping) {
// operation, mapping
// return modified item
}
// Function version
foreach ($items as $item) {
$res[] = myFn($item, &$mapping);
}
// Closure version
$closure = function($item) {
// operation, mapping
// return modfied item
};
foreach ($items as $item) {
$res[] = $closure($item, &$mapping);
}
Or is there a better solution?