久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      分享一個生成文件層級樹類

      分享一個生成文件層級樹類

      根據(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 . '&nbsp;&nbsp;&nbsp;';                 $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 . '&nbsp;');                 $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教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號