zoukankan      html  css  js  c++  java
  • 在属性方法内写匿名方法 递归文件

        #货物当前所有的版本文件夹
        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);
        }
     
  • 相关阅读:
    nat
    ICE协议下NAT穿越的实现(STUN&TURN)
    比特币源码分析--端口映射
    IO复用,AIO,BIO,NIO,同步,异步,阻塞和非阻塞 区别(百度)
    从数据的角度带你深入了解IPFS
    IPFS 到底是怎么工作的?
    从数据的角度带你深入了解IPFS
    IPFS
    IPFS中文简介
    bootstrap 表单验证 dem
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/14376204.html
Copyright © 2011-2022 走看看