Rozpocznij nową kolumnę, gdy readdir przejdzie do nowego katalogu

Pierwotna przyczyna:

Używam readdir do pobierania nazw plików z wielu katalogów. Zastanawiałem się, czy istnieje sposób na uporządkowanie danych, aby za każdym razem, gdy uruchamia nowy katalog, tworzy nową kolumnę, tj.

---| user1  | user2  | user3  |
---| file1a | file2a | file3a |
---| file1b | file2b | file3b |
---| file1c | file2c | file3c |
---| file1d |   ^    | file3d |
---| file1e |   |    |   ^    |
---|    ^   |  end   |   |    |
---|    |   |  dir2  |  end   |
---|   end  | #start |  dir3  |
---|   dir1 |  col3  |  etc.  |
---| #start |        |        |
---|  col2  |        |        |

jeśli to możliwe, byłoby świetnie; jeśli chodzi o wyświetlanie nazw użytkowników na górze, mam już tę część. Muszę tylko wiedzieć, czy można wykonać część kolumn, a jeśli tak, jak to zrobić.

Kodowanie, które mam do tej pory to:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
<?php
if ($handle = opendir('Users/')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {


            echo '<th>';
            echo "$entry\n";
            echo '</th>';
            }
                  }
        }           
?>

<?php

 $folders = @scandir('Users');  
    foreach($folders as $item){
         if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
                continue;

        if (is_dir("Users/$item")){
            $target_folders = @scandir("Users/$item/uploaded/");
            foreach($target_folders as $target_item){
                if ((!preg_match("/^[.]/",$target_item)) || (!is_dir("Users/$item/uploaded/$target_item")));
                if ((substr($target_item, 0, 1) == '.'))
                        continue;
                echo '<tr>';
                echo '<td>';        
                echo $target_item;
                echo '</td>';
                echo '</tr>';
                                    }
                            }
                 }
?>
</table>
</body>
</html>

questionAnswers(1)

yourAnswerToTheQuestion