Una micro ottimizzazione. Il manuale PHP per la opendir ci dice

Return Values

Returns a directory handle resource on success, or FALSE on failure. If path is not a valid directory or the directory can not be opened due to permission restrictions or filesystem errors, opendir() returns FALSE and generates a PHP error of level E_WARNING. You can suppress the error output of opendir() by prepending '@' to the front of the function name.
quindi il codice

codice:
foreach ($array_delle_dir as $subDir) {
    if($dh = @opendir($path.$subDir)){
        if(is_dir($path.$subDir)){
            ...               
        }
    }    
    @closedir($dh);
}
Lo puoi scrivere come

codice:
foreach ($array_delle_dir as $subDir)
    if(($dh = @opendir($path.$subDir))!==false){        
        ...   
       closedir($dh);                    
    }
Nel senso che il foreach non ha bisogno del blocco {} perchè esegue solo l'istruzione if, il closedir viene spostato dentro il blocco then dell'if perchè, è inutile cercare di chiudere qualcosa che potrebbe non essere aperto, invece nel blocco then dell'if sei certo che il $dh ha un handle alla directory che chiudi correttamente. Ti risparmi le n chiamate alla funzione is_dir perchè, se la directory viene aperta la usa, altrimenti la ignora.