0

Is there any reason to use one foreach syntax instead of another?

foreach (array_expression as $value) {
    // statements
}

or

foreach (array_expression as $value) :
    // statements
endforeach; 
jcropp
  • 1,236
  • 2
  • 10
  • 29

2 Answers2

1

They are completely equivalent, as stated in the official manual of PHP.

See here for more info: http://php.net/manual/en/control-structures.foreach.php

1

Most times the foreach ... endforeach version is used in "templates". So it's easier for you to follow the logic of templates.

bukart
  • 4,906
  • 2
  • 21
  • 40