Skip to content

Instantly share code, notes, and snippets.

@jk
Created December 3, 2014 10:31
Show Gist options
  • Save jk/fdd713f80ffcba1a63ff to your computer and use it in GitHub Desktop.
Save jk/fdd713f80ffcba1a63ff to your computer and use it in GitHub Desktop.
Map array with closure
<?php
$array = range(0,4);
$add = 10;
// Beware: importing variables (i.e. $add) copies the variable, you can out-out by value (i.e. &$add)
$array = array_map(function($value) use ($add) {
return $value + $add;
}, $array);
var_dump($array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment