Skip to content

Instantly share code, notes, and snippets.

@alliejones
Last active December 15, 2015 14:09
Show Gist options
  • Save alliejones/5272164 to your computer and use it in GitHub Desktop.
Save alliejones/5272164 to your computer and use it in GitHub Desktop.
Anonymous functions in PHP 5.3
<?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