比较俩个二维数组,返回差集
2019-01-19 本文已影响0人
我的楼兰0909
/**
* 比较俩个二维数组,返回差集
*/
public static function compareFile($dir_name_new,$dir_name)
{
ini_set('memory_limit', '-1');
$md5_folder_new = Finance::md5_folder($dir_name_new);
$md5_folder = Finance::md5_folder($dir_name);
if($md5_folder_new == $md5_folder){
return [];
}else{
$new_files = Finance::getFiles($dir_name_new);
$new_data = [];
$files = Finance::getFiles($dir_name);
$data = [];
foreach ($new_files as $file) {
$val['file_name'] = $file;
$val['md5_file'] = md5_file($dir_name_new.$file);
$new_data[] = $val;
}
foreach ($files as $file) {
$val['file_name'] = $file;
$val['md5_file'] = md5_file($dir_name.$file);
$data[] = $val;
}
$result = array_filter($new_data, function($v) use ($data) {
return ! in_array($v, $data);
});
return $result?array_column($result, 'file_name'):[];
}
}