欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

php生成文件層級樹類

今天小編給大家分享的是php生成文件層級樹類的方法。小編覺得挺實用的,為此分享給大家做個參考。一起跟隨小編過來看看吧。                                                           

成都創(chuàng)新互聯(lián)是專業(yè)的牟定網(wǎng)站建設(shè)公司,牟定接單;提供成都網(wǎng)站設(shè)計、網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行牟定網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

根據(jù) php 遞歸讀取文件夾生成文件樹

class Tree
{
    public $arr = array();
    public $icon = array(
        '│',
        '├─',
        '└─'
    );
    public $ret;
    public function set_tree($arr = array())
    {
        $this->arr = $arr;
    }
    public function get_child($myid)
    {
        $newarr = array();
        if (is_array($this->arr)) {
            foreach ($this->arr as $id => $a) {
                if ($a['pid'] == $myid) {
                    $newarr[$id] = $a;
                }
            }
        }
        return $newarr ? $newarr : false;
    }
    //獲取帶格式數(shù)組
    public function getArray($myid = 0, $sid = 0, $adds = '')
    {
        $number = 1;
        $child = $this->get_child($myid);
        if (is_array($child)) {
            $total = count($child);
            foreach ($child as $a) {
                $j = $k = '';
                if ($number == $total) {
                    $j .= $this->icon[2];
                } else {
                    $j .= $this->icon[1];
                    $k = $adds ? $this->icon[0] : '';
                }
                $spacer = $adds ? $adds . $j : '';
                $a['name'] = $spacer . ' ' . $a['name'];
                $this->ret[] = $a;
                $fd = $adds . $k . '   ';
                $this->getArray($a['id'], $sid, $fd);
                $number++;
            }
        }
        return $this->ret;
    }
    //select
    public function get_tree($myid, $str, $sid = 0, $adds = '')
    {
        $number = 1;
        $child = $this->get_child($myid);
        if (is_array($child)) {
            $total = count($child);
            foreach ($child as $a) {
                $id = $a['id'];
                $j = $k = '';
                if ($number == $total) {
                    $j .= $this->icon [2];
                } else {
                    $j .= $this->icon [1];
                    $k = $adds ? $this->icon [0] : '';
                }
                $spacer = $adds ? $adds . $j : '';
                $select = $id == $sid ? 'selected' : '';
                $this->ret .= sprintf($str, $id, $select, $spacer, $a['name']);
                $this->get_tree($id, $str, $sid, $adds . $k . ' ');
                $number++;
            }
        }
        return $this->ret;
    }
    //文件夾目錄
    public function read_all_dir($dir, $onlyDir = true, $ignore = [])
    {
        $result = array();
        $handle = opendir($dir);
        if ($handle) {
            while (($file = readdir($handle)) !== false) {
                if (in_array($file, $ignore)) continue;
                if ($file != '.' && $file != '..') {
                    $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
                    if (is_dir($cur_path)) {
                        $result[$file] = $this->read_all_dir($cur_path, $onlyDir);
                    } else {
                        if (!$onlyDir) {
                            $result[] = $file;
                        }
                    }
                }
            }
            closedir($handle);
        }
        return $result;
    }
    //數(shù)組轉(zhuǎn)換
    public function arrshift($array, $pid = 0)
    {
        static $r = [];
        static $index = 1;
        if (is_array($array) && count($array) > 0) {
            foreach ($array as $k => $v) {
                $r[] = array(
                    'id' => $index,
                    'pid' => $pid,
                    'name' => is_array($v) ? $k : $v
                );
                $index++;
                $this->arrshift($v, $index - 1);
            }
        }
        return $r;
    }
}

使用示例

$tree = new Tree ();
//文件夾遍歷
$data = $tree->read_all_dir(realpath('../file_dir'), false, ['.git', '.idea', 'vendor']);
//轉(zhuǎn)換成[['id','pid','name']]的二維數(shù)組
$data = $tree->arrshift($data);
$tree->set_tree($data); 
$data = $tree->getArray();
foreach ($data as $value) {
    echo $value['name'];
    echo '<br/>';
    echo '<br/>';
}

上文描述的就是php生成文件層級樹類的方法,具體使用情況還需要大家自己動手實驗使用過才能領(lǐng)會。如果想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁標題:php生成文件層級樹類
本文地址:http://chinadenli.net/article34/gphjpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、搜索引擎優(yōu)化、用戶體驗App設(shè)計、微信小程序網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
国产又粗又爽又猛又黄的| 国产精品激情对白一区二区| 日韩欧美一区二区亚洲| 亚洲国产一级片在线观看| 亚洲男人天堂成人在线视频| 欧美日韩少妇精品专区性色| 国产成人午夜av一区二区| 亚洲性生活一区二区三区| 少妇肥臀一区二区三区| 亚洲精品国产第一区二区多人| 五月天丁香亚洲综合网| 91欧美日韩国产在线观看| 女人精品内射国产99| 91人妻人人精品人人爽| 久久精品国产亚洲av久按摩| 久久热在线视频免费观看| 亚洲淫片一区二区三区| 91免费一区二区三区| 91精品欧美综合在ⅹ| 国产免费成人激情视频| 亚洲精选91福利在线观看| 国产欧美日韩综合精品二区| 国产女同精品一区二区| 日韩欧美综合在线播放| 免费观看一级欧美大片| 亚洲婷婷开心色四房播播| 精品亚洲一区二区三区w竹菊| av在线免费观看在线免费观看| 麻豆精品在线一区二区三区| 日韩欧美精品一区二区三区| 国产欧美日韩精品一区二区| 欧美日韩综合在线第一页| 成人精品一区二区三区综合| 亚洲男人的天堂就去爱| 国产一级性生活录像片| 日本少妇中文字幕不卡视频| 欧美性猛交内射老熟妇| 五月激情五月天综合网| 日韩一区二区三区高清在| 久久香蕉综合网精品视频| 午夜福利国产精品不卡|