在属性方法内写匿名方法 递归文件
#货物当前所有的版本文件夹 public function getDirList() { $root_path = Env::get('root_path'); $fileDirectory = $root_path . '/public/codeZip'; $newFile = []; $tree = function ($fileDirectory, $newFile) use (&$treet) { if (is_dir($fileDirectory)) { $file = scandir($fileDirectory, 1); if ($file) { foreach ($file as $key => $value) { if ($value != '.' && $value != '..') { if (is_dir($fileDirectory . '/' . $value)) { return $treet($fileDirectory . '/' . $value, $newFile); } if ($value !== '.' && $value !== '..') { $newFile[] = $value; } } } return $newFile; } } return []; }; $dirList = $greet($fileDirectory, $newFile); return $this->returnData(0, '成功', $dirList); }
#按修改时间倒叙
public function getDirList()
{
$root_path = Env::get('root_path');
$fileDirectory = $root_path . '/public/codeZip';
$newFile = [];
$greet = function ($fileDirectory, $newFile, &$seconds) use (&$greet) {
if (is_dir($fileDirectory)) {
$file = scandir($fileDirectory, 1);
if ($file) {
foreach ($file as $key => $value) {
if ($value != '.' && $value != '..') {
if (is_dir($fileDirectory . '/' . $value)) {
return $greet($fileDirectory . '/' . $value, $newFile, $seconds);
}
if ($value !== '.' && $value !== '..') {
$newFile[$seconds]['fileName'] = $value;
$newFile[$seconds]['uTime'] = filemtime($fileDirectory . '/' . $value);
}
$seconds += 1;
}
}
return $newFile;
}
}
return [];
};
$seconds = 0;
$dirList = $greet($fileDirectory, $newFile, $seconds);
$uTime = array_column($dirList, 'uTime');
array_multisort($uTime, SORT_DESC, $dirList);
$dirList = array_column($dirList, 'fileName');
return $this->returnData(0, '成功', $dirList);
}