Skip to content

Instantly share code, notes, and snippets.

@raphaeldealmeida
Created February 22, 2012 13:45
Show Gist options
  • Save raphaeldealmeida/1885226 to your computer and use it in GitHub Desktop.
Save raphaeldealmeida/1885226 to your computer and use it in GitHub Desktop.
com closure
<?php
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892);
function criarFiltro($maiorQue){
return function ($x) use ($maiorQue){
return $x > $maiorQue;
};
}
$filtro100 = criarFiltro(100);
$filtro50 = criarFiltro(50);
//output: array(244, 700, 892)
array_filter($lista, $filtro100);
//output: array(56, 65, 96, 244, 700, 892)
array_filter($lista, $filtro50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment