original_string: public static function get_tree(string $dir, bool $only_dir = false, callable $filter = null, bool $hidden = false): array
    {
      $r = [];
      $dir = self::clean($dir);
      $dirs = self::get_dirs($dir, $hidden);
      if ( \is_array($dirs) ){
        foreach ( $dirs as $d ){
          $x = [
            'name' => $d,
            'type' => 'dir',
            'num_children' => 0,
            'items' => self::get_tree($d, $only_dir, $filter, $hidden)
          ];
          $x['num_children'] = \count($x['items']);
          if ( $filter ){
            if ( $filter($x) ){
              $r[] = $x;
            }
          }
          else{
            $r[] = $x;
          }
        }
        if ( !$only_dir ){
          $files = self::get_files($dir, false, $hidden);
          foreach ( $files as $f ){
            $x = [
              'name' => $f,
              'type' => 'file',
              'ext' => bbn\str::file_ext($f)
            ];
            if ( $filter ){
              if ( $filter($x) ){
                $r[] = $x;
              }
            }
            else{
              $r[] = $x;
            }
          }
        }
      }
      return $r;
    }
code: public static function get_tree(string $dir, bool $only_dir = false, callable $filter = null, bool $hidden = false): array
    {
      $r = [];
      $dir = self::clean($dir);
      $dirs = self::get_dirs($dir, $hidden);
      if ( \is_array($dirs) ){
        foreach ( $dirs as $d ){
          $x = [
            'name' => $d,
            'type' => 'dir',
            'num_children' => 0,
            'items' => self::get_tree($d, $only_dir, $filter, $hidden)
          ];
          $x['num_children'] = \count($x['items']);
          if ( $filter ){
            if ( $filter($x) ){
              $r[] = $x;
            }
          }
          else{
            $r[] = $x;
          }
        }
        if ( !$only_dir ){
          $files = self::get_files($dir, false, $hidden);
          foreach ( $files as $f ){
            $x = [
              'name' => $f,
              'type' => 'file',
              'ext' => bbn\str::file_ext($f)
            ];
            if ( $filter ){
              if ( $filter($x) ){
                $r[] = $x;
              }
            }
            else{
              $r[] = $x;
            }
          }
        }
      }
      return $r;
    }
code_tokens: public static function get_tree ( string $ dir , bool $ only_dir = false , callable $ filter = null , bool $ hidden = false ) : array { $ r = [ ] ; $ dir = self :: clean ( $ dir ) ; $ dirs = self :: get_dirs ( $ dir , $ hidden ) ; if ( \ is_array ( $ dirs ) ) { foreach ( $ dirs as $ d ) { $ x = [ 'name' => $ d , 'type' => 'dir' , 'num_children' => 0 , 'items' => self :: get_tree ( $ d , $ only_dir , $ filter , $ hidden ) ] ; $ x [ 'num_children' ] = \ count ( $ x [ 'items' ] ) ; if ( $ filter ) { if ( $ filter ( $ x ) ) { $ r [ ] = $ x ; } } else { $ r [ ] = $ x ; } } if ( ! $ only_dir ) { $ files = self :: get_files ( $ dir , false , $ hidden ) ; foreach ( $ files as $ f ) { $ x = [ 'name' => $ f , 'type' => 'file' , 'ext' => bbn \ str :: file_ext ( $ f ) ] ; if ( $ filter ) { if ( $ filter ( $ x ) ) { $ r [ ] = $ x ; } } else { $ r [ ] = $ x ; } } } } return $ r ; }
docstring: Return an array with the tree of the folder's content.
  
  ```php
  \bbn\x::dump(\bbn\file\dir::get_tree("/home/data/test"));
  /* (array)
  [
  [
  "name"  =>  "/home/data/test/Folder",
  "type"  =>  "dir",
  "num_children"  =>  0,
  "items"  =>  [],
  ],
  [
  "name"  =>  "/home/data/test/Folder_test",
  "type"  =>  "dir",
  "num_children"  =>  1,
  "items"  =>  [
  [
  "name"  =>  "/home/data/test/Folder_test/image.png",
  "type"  =>  "file",
  "ext"  =>  "png",
  ],
  ],
  ],
  ]
  \bbn\x::dump(\bbn\file\dir::get_tree("/home/data/test", true) );
  /* (array)
  [
  [
  "name"  =>  "/home/data/test/Folder",
  "type"  =>  "dir",
  "num_children"  =>  0,
  "items"  =>  [],
  ],
  [
  "name"  =>  "/home/data/test/Folder_test",
  "type"  =>  "dir",
  "num_children"  =>  0,
  "items"  =>  [],
  ],
  ]
  \bbn\x::dump(\bbn\file\dir::get_tree("/home/data/test", false, false, true) );
  /* (array)
  [
  [
  "name"  =>  "/home/data/test/Folder",
  "type"  =>  "dir",
  "num_children"  =>  1,
  "items"  =>  [
  [
  "name"  =>  "/home/data/test/Folder/.doc.pdf",
  "type"  =>  "file",
  "ext"  =>  "pdf",
  ],
  ],
  ],
  [
  "name"  =>  "/home/data/test/Folder_test",
  "type"  =>  "dir",
  "num_children"  =>  1,
  "items"  =>  [
  [
  "name"  =>  "/home/data/test/Folder_test/image.png",
  "type"  =>  "file",
  "ext"  =>  "png",
  ],
  ],
  ],
  ]
  ```
  
  @param string $dir The directory's path.
  @param bool $only_dir If set to true will just return the folder(s), if false will include in the resulr also the file(s). Default = false.
  @param callable $filter Filter function
  @param bool $hidden If set to true will also return the hidden file(s)/folder(s)
  @return array
docstring_tokens: Return an array with the tree of the folder s content .