Created
February 22, 2012 13:45
-
-
Save raphaeldealmeida/1885226 to your computer and use it in GitHub Desktop.
com closure
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 | |
$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