Logo

Programming-Idioms

History of Idiom 57 > diff from v12 to v13

Edit summary for version 13 by :

Version 12

2015-08-19, 15:06:48

Version 13

2015-08-19, 15:07:33

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 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 */

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 */