Logo

Programming-Idioms

History of Idiom 57 > diff from v19 to v20

Edit summary for version 20 by :

Version 19

2015-08-23, 00:46:37

Version 20

2015-08-26, 21:12:42

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 p($element) {
    
}

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

$y = array_filter ($x, "p");
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 */

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.