• 在属性方法内写匿名方法 递归文件


        #货物当前所有的版本文件夹
        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);
        }
     
  • 相关阅读:
    创建数据库链
    redis命令
    redis.conf文件配置信息
    mybatis调用存储过程实现
    oracle游标使用遍历3种方法
    Proud Merchants
    Bag Problem
    Watch The Movie
    Accepted Necklace
    Bone Collector II
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/14376204.html
Copyright © 2020-2023  润新知