如何通过array_filter
运行多个参数?这是我的函数,包含多个参数和array_filter
代码
function is_txt($file, $user) {
return preg_match('/backup-[0-9]+\.[0-9]+\.[0-9]+_[0-9]{2}-[0-9]{2}-[0-9]{2}_'.$user.'.tar.gz/', $file) > 0;
}
....
$list = ftp_nlist($conn_id, $ftp_dir);
$filtered = array_filter($list, 'is_txt');
if(count($filtered)){
foreach( $filtered as $name => $file){
echo $file;
echo "<br>";
}
答案 0 :(得分:0)
您可以使用匿名函数:
$filtered = array_filter($list, function($file) use ($user) {
return is_txt($file, $user);
});
※PHP版本需要&gt; = 5.3