php数组过滤函数问题与变量

I have a problem using a variable inside this array filter:

$lteam_id = 25;
$flt_lteam = array_filter($events, function($obj)

{
return $obj['team_id'] == $lteam_id && $obj['type'] == 'kick' && $obj['minute'] <= 75 ;
}); 

As soon as I replace $lteam_idwith 25 it works and I get a result. Using the variable results in an array(0) { }... Hope you can help me here on using the variables correctly.

You use anonymous function, so you can use use statement to pass variable to it:

$lteam_id = 25;
$flt_lteam = array_filter($events, function($obj) use ($lteam_id)
{
    return $obj['team_id'] == $lteam_id && $obj['type'] == 'kick' && $obj['minute'] <= 75 ;
}); 

$lteam_id is not accessible in closure inside array_filter(). either pass the variable as argument of the closure or use using

$flt_lteam = array_filter($events, function($obj) using($lteam_id)

{
return $obj['team_id'] == $lteam_id && $obj['type'] == 'kick' && $obj['minute'] <= 75 ;
});