Page 1 of 1

why it use this ?

Posted: Sun Aug 29, 2010 8:22 am
by everydayrun

Code: Select all

<body>
<h1>News Articles</h1>
<?php foreach ($articles as $row) { ?>
<h2><?php echo $row->headline ?></h2>
<p>
<?php echo $row->body ?>
</p>
<?php } ?>
</body>
why it use " { ?>" and "<?php } ?>"? i feel the "{" is surplus.

Re: why it use this ?

Posted: Sun Aug 29, 2010 9:52 am
by Weirdan
That's a part of foreach syntax for when the loop body includes more than one statement. Using alternative syntax in templates make more sense IMO (and if you have short_tag enabled it's even more sensible):

Code: Select all

<body>
<h1>News Articles</h1>
<? foreach ($articles as $row) : ?>
<h2><?= $row->headline ?></h2>
<p><?= $row->body ?></p>
<? endforeach; ?>
</body>