Q:

What is the logic of several  in one file

I can’t find answer anywhere or just don’t get it.
So, I have HTML and PHP code combined in my PHP file. In books it’s written that the code in <?php ?> are executed on server only and html will display in browser. But I don’t understand THIS:
<?php if ($a = $b) { ?>
   <p>Text when condition is true</p>
<?php } else { ?>
   <p>Text when condition is false</p>
<?php } ?>

The above is working in browser but I don’t understand why it doesn't output error
or at least it should output both sentences.
For me it seems that the statement is broken into peaces and the only way when it should work is:
<?php 
if ($a = $b) 
{           
   echo "<p>Text when condition is true</p>"
} else { 
   echo "<p>Text when condition is false</p>"
}      
?>

What do I miss here?

A:

It's just the way it works. PHP is a templating language and you can play tricks like that. 
A piece of HTML in between two PHP blocks is interpreted as "output these characters". 
It's generally a good idea to keep this kind of intermixing of PHP and HTML to a minimum, though - any serious back-end code that goes beyond simple if/else structures or loops should be in a separate location.

