Skip to content

Instantly share code, notes, and snippets.

@prufrock
Created May 2, 2013 03:34
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 prufrock/5500000 to your computer and use it in GitHub Desktop.
Save prufrock/5500000 to your computer and use it in GitHub Desktop.
Using some of php's built in array functions to do something a little similar to erlang's list comprehensions.
<?php
$a = array(1, 2, 3, 4, 5);
$f = function($a) { return (($a * 2));};
$b = array_values(array_map($f, array_filter($a, function($a) {return ($a > 2);})));
var_dump($b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment