Logo

Programming-Idioms

History of Idiom 57 > diff from v13 to v14

Edit summary for version 14 by :

Version 13

2015-08-19, 15:07:33

Version 14

2015-08-20, 06:21:28

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Code
function predicate($element) {
    
}

$y = array_filter ($x, "predicate");
Code
function p($element) {
    
}

$y = array_filter ($x, "p");
Comments bubble
/* filtering code goes to function predicate which is called for each element of array $x,
and if function returns true, that element goes to array $y */

Comments bubble
/* filtering code goes to function p which is called for each element of array $x,
and if function returns true, that element goes to array $y */