public static function getAllSubdirectories($dir, $subdir = false) {
        $path = '';
        $stack[] = $dir;
        while ($stack) {
            $thisdir = array_shift($stack);
            if ($dircont = scandir($thisdir)) {
                $i = 0;
                while (isset($dircont[$i])) {
                    if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
                        $current_file = "{$thisdir}/{$dircont[$i]}";
                        if (is_dir($current_file)) {
                            $temp = explode("/", $current_file);
                            $path[$temp[count($temp) - 1]] = "{$thisdir}/{$dircont[$i]}";

                            if ($subdir === true)
                                $stack[] = $current_file;
                        }
                    }
                    $i++;
                }
            }
        }
        return $path;
    }
public static function getAllSubdirectories($dir, $subdir = false) {
        $path = '';
        $stack[] = $dir;
        while ($stack) {
            $thisdir = array_shift($stack);
            if ($dircont = scandir($thisdir)) {
                $i = 0;
                while (isset($dircont[$i])) {
                    if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
                        $current_file = "{$thisdir}/{$dircont[$i]}";
                        if (is_dir($current_file)) {
                            $temp = explode("/", $current_file);
                            $path[$temp[count($temp) - 1]] = "{$thisdir}/{$dircont[$i]}";

                            if ($subdir === true)
                                $stack[] = $current_file;
                        }
                    }
                    $i++;
                }
            }
        }
        return $path;
    }
public static function getAllSubdirectories ( $ dir , $ subdir = false ) { $ path = '' ; $ stack [ ] = $ dir ; while ( $ stack ) { $ thisdir = array_shift ( $ stack ) ; if ( $ dircont = scandir ( $ thisdir ) ) { $ i = 0 ; while ( isset ( $ dircont [ $ i ] ) ) { if ( $ dircont [ $ i ] !== '.' && $ dircont [ $ i ] !== '..' ) { $ current_file = "{$thisdir}/{$dircont[$i]}" ; if ( is_dir ( $ current_file ) ) { $ temp = explode ( "/" , $ current_file ) ; $ path [ $ temp [ count ( $ temp ) - 1 ] ] = "{$thisdir}/{$dircont[$i]}" ; if ( $ subdir === true ) $ stack [ ] = $ current_file ; } } $ i ++ ; } } } return $ path ; }
Get all subdirectories of directory

@param string $dir directory location
@param boolean $subdir include subdirectories of subdirectory
@return array
Get all subdirectories of directory