不能在不重复的情况下将两种类型的文件混合在一起

Cant glob two types files without repeating itself

我知道我有两个 foreach 但是当我将 txt 的 glob 分配给 var 时它不起作用。它应该为找到的每个 html 文件写入相应的 txt 文件等,仅一次。我怎么摇这个?

<?php

echo '<h2>Escolha o Esquema de MetaDados a utilizar</h2>';
echo '<table cellspacing="0" cellpadding="0" border="0" class="table">';
echo '<tr>';
echo '<th>Esquema de MetaDados</th>';
echo '<th>Descrição</th>';
echo '</tr>';


foreach (glob("Templates/Dinamico/*.html") as $filename) {
    foreach (glob("Templates/Dinamico/*.txt") as $txtname) {
        $fileH = basename($filename, ".html");
        $fileT = basename($txtname, ".txt");
        if ($fileH = $fileT) {
            $txt = file_get_contents($txtname);
            if ($filename != "Templates/Dinamico/formD1.html") {
                echo '<tr>';
                echo '<td>';
                echo "<a strong href='" . $filename . "'>" . $fileH . "</a>";
                echo '</td>';
                echo '<td>';
                echo $txt;
                echo '</td>';
                echo '</tr>';
                //just checking the files
                echo "$filename size " . filesize($filename) . "\n";
            }
        }
    }
}

<?php

    echo '<h2>Escolha o Esquema de MetaDados a utilizar</h2>';
    echo '<table cellspacing="0" cellpadding="0" border="0" class="table">';
    echo '<tr>';
    echo '<th>Esquema de MetaDados</th>';
    echo '<th>Descrição</th>';
    echo '</tr>';

          foreach (glob("Templates/Dinamico/*.html") as $filename) {
          foreach(glob("Templates/Dinamico/*.txt") as $txtname){ 
           $fileH= basename($filename,".html");
           $fileT= basename($txtname,".txt");   
          if($fileH==$fileT){ 
          $txt= file_get_contents ( $txtname); 
        if($filename != "Templates/Dinamico/formD1.html"){ 
            echo'<tr>';
            echo'<td>';
            echo "<a name='".$fileH."'strong href='Templates/Dinamico/formD1.php?id=$fileH'>".$fileH."</a>";
            echo'</td>';
            echo'<td>';
            echo $txt;
            echo'</td>';
            echo'</tr>';

}
}
}
}

    ?>