Skip to content

Instantly share code, notes, and snippets.

@marcioAlmada
Last active September 30, 2015 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcioAlmada/8e093863460da624e06e to your computer and use it in GitHub Desktop.
Save marcioAlmada/8e093863460da624e06e to your computer and use it in GitHub Desktop.
<?php declare(strict_types=1);
function crunch_data(array $data, callable(int $left, int $right): int $callback): array {
$result = [];
foreach($data as $left => $right) $result[] = $callback($left, $right);
return $result;
}
$crunched = crunch_data([1 => 2, 3 => 4], function(int $left, int $right): int {
return $left * $right;
});
var_dump($crunched);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment