主要是为了在循环创建HTML时可以使开始和结束语句更清晰:
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以获取HTML 页面),备用语法(endforeach)的形式可以使您的大脑更容易解析。 使用常规样式时,结帐}可以自己保留,这样很难说出他们实际要结帐的内容。