Last active
December 15, 2015 14:09
-
-
Save alliejones/5272164 to your computer and use it in GitHub Desktop.
Anonymous functions in PHP 5.3
This file contains hidden or 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 | |
$my_array = array(1, 2, 3); | |
$new_array = array_map(function($num) { return $num * 2; }, $my_array); // $new_array: [2, 4, 6] | |
// Why the arguments are in the opposite order, I have no idea ... | |
$new_array2 = array_filter($my_array, function($num) { return $num % 2 == 0; }); // $new_array2: [2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment