它主要是因为你可以使创建html in循环中的开始和结束语句更清晰:
while ($record = mysql_fetch_assoc($rs)) { ?>
if (!$record['deleted']): ?>
foreach ($display_fields as $field): ?>
= $record[$field] ?>endforeach; ?>
foreach ($actions as $action): ?>
= $action ?>
endforeach; ?>
else: ?>
record = $record['id'] ?> has been deletedendif; ?>
endwhile; ?>
与
while ($record = mysql_fetch_assoc($rs)) { ?>
if (!$record['deleted']) { ?>
foreach ($display_fields as $field) { ?>
= $record[$field] ?>} ?>
foreach ($actions as $action) { ?>
= action ?>
} ?>
} else { ?>
record = $record['id'] ?> has been deleted} ?>
} ?>
希望我的例子足以证明,一旦你有几层嵌套循环,并且缩进被所有的php打开/关闭标签和包含的html抛出(或许你必须缩进html一定的方式,让你的页面你想要的方式),alternate syntax(endforeach)窗体可以使事情更容易你的大脑来解析。使用正常的风格,关闭}可以自己留下,使得很难知道他们实际关闭。