0
我對代碼重複有點奇怪的問題。有大量的循環是這樣的: 偏執:避免代碼重複/在循環之後
$prev_name = null;
$clone = null;
while($row = mysql_fetch_assoc($res)){
if($prev_name != $row['req']){
if($prev_name){
while($clone <= $end){
echo '<td>-</td>';
$clone->step();
}
echo '</tr>';
}
echo '<tr><td>' . htmlspecialchars($prev_name = $row['req']) . '</td>';
$clone = clone $start;
}
$rowdate = date_create($row['date']);
while($clone < $rowdate){
echo '<td>-</td>';
$clone->step();
}
echo '<td>' . $row[$field] . '</td>';
$clone->step();
}
if($prev_name){
while($clone <= $end){
echo '<td>-</td>';
$clone->step();
}
echo '</tr>';
}
正如你看到的,如果()循環之後是在環2擋,如果()一樣。是否有可能減少這種重複?