Logo

Programming-Idioms

History of Idiom 57 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-08-18, 13:48:07

Version 12

2015-08-19, 15:06:48

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");
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 */