zoukankan      html  css  js  c++  java
  • php嵌套数据

    <?php
    
    header('Content-Type: text/html; charset=utf-8');
    $path = './';
    $list = readDirsNested($path);
    echo '<pre>';
    print_r($list);
    
    /**
     * @param 目录地址
     */
    function readDirsNested($path) {
        $nested = array();//存储当前目录下所有的文件
        $dir_handle = openDir($path);
        while(false !== $file=readDir($dir_handle)) {
            if ($file=='.' || $file=='..') continue;
    
            //创建当前文件信息
            $fileinfo = array();
            // $fileinfo['name'] = $file;
            $fileinfo['name'] = iconv('gbk', 'utf-8', $file);
    
            //判断当前是否为目录
            if(is_dir($path . '/' . $file)) {
                //是目录
                $fileinfo['type'] = 'dir';
                $func_name = __FUNCTION__;
                $fileinfo['nested'] = $func_name($path . '/' . $file);
            } else {
                //是文件
                $fileinfo['type'] = 'file';
            }
            //存入$nested数组内
            $nested[] = $fileinfo;
        }
    
        closeDir($dir_handle);
        return $nested;
    }
  • 相关阅读:
    Vue自定义指令
    Vue实例生命周期
    Vue学习目录
    Vue表单控件绑定
    Vue事件处理
    Vue数组更新及过滤排序
    Vue模板逻辑
    Vue模板内容
    Vue实例对象的数据选项
    Vue组件基础用法
  • 原文地址:https://www.cnblogs.com/huodaihao/p/7190927.html
Copyright © 2011-2022 走看看