0

I understand that the below control flow works. My question is more conceptual: How does line 2 or line 4 run as just HTML in the midst of a PHP if/else without needing any echos or other PHP syntax? And if the condition is false, how does PHP just pick up later on at the else? I guess i'm just baffled at how the code makes sense and that it actually works.

1  <?php if (condition): ?>
2  //html code to run if condition is true
3  <?php else: ?>
4  //html code to run if condition is false
5  <?php endif ?>
Govind Rai
  • 14,406
  • 9
  • 72
  • 83

1 Answers1

1

When php is processed line by line and IF condition is encountered, then if the condition is true the processing continues to next line. Otherwise process looks for the end of END OF IF or ELSE IF etc.

Anything which is not between is output as it is. But in the case of HTML in middle of two PHP blocks if there is any conditional statement then the HTML between condition is only outputted based on the result of the conditions.

You can find more details at http://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html

Zeeshan
  • 54
  • 6