PHP array_filter with arguments

if you are using php 5.3 and above, you can use closure to simplify your code:

$NUM = 5;
$items = array(1, 4, 5, 8, 0, 6);
$filteredItems = array_filter($items, function($elem) use($NUM){
    return $elem < $NUM;
});

Leave a Comment