foreach ($array as $value) {
code to be executed;
}
VS
<?php foreach($arr as $item):?>
<!--do stuff -->
<?php endforeach; ?>
I mostly used brackets
when using foreach(){...}
loop , but What is foreach(): ... endforeach;
loop for?
Is there any difference between these two types foreach(){} vs foreach():...endforeach;
or they are same in php?
and in which scenario we used them or is there any technical difference between them?
and which one is the better approach for looping the resultset?
Thanks for Help Please.
They are exact same thing with two different syntax.
PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.
Reference : https://php.net/manual/en/control-structures.alternative-syntax.php