I created 2 simple examples:
First example:
<?php $arr = array(1,2,3,4,5); ?> <?php foreach ($arr as $element) ?> <?php { ?> <?php echo $element; ?> <?php } ?>
output:
5 //Is this result wrong?
Second example:
<?php $arr = array(1,2,3,4,5); ?> <?php foreach ($arr as $element) { ?> <?php echo $element; ?> <?php } ?>
output:
12345
What did I miss about PHP syntax?
I know that there is an alternative foreach syntax, but, in my opinion, both of the examples shown should lead to the same conclusion. (Code tested with PHP version: 5.6.12)
Edit:
I know that tags are not needed on every line. More precisely: I want to know why two examples give me two different results?
source share