Created
December 3, 2014 10:31
-
-
Save jk/fdd713f80ffcba1a63ff to your computer and use it in GitHub Desktop.
Map array with closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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