PHP: Adding Custom Closure Parameter

PHP supported closure(anonymous function) since PHP 5.3. Sometimes extra parameter is needed to pass to those closure. PHP provide use keyword to do this job. Here is an example with array_filter():
$array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$param = 5; // custom parameter
 
$r = array_filter($array, function($i) use ($param) { return $i < $param; });
// checking result
print_r($r);