title: PHP Conditional Followed by Closing Tag
body: <p>I am kind of confused about <strong>how</strong> the below code works.  In my head I am imagining each php block being executed as a whole and rendered to HTML.  The fact that the first block is kind of incomplete with a hanging brace doesn't play nicely with how I imagine PHP to work.  What does the PHP module do when it gets to a PHP closing tag?  How is it that code inside the PHP tags can effect the output of plaintext outside of the PHP tags, i.e. only conditionally outputting the form?</p>
  
  <p>I would have thought that to accomplish the below you would have actually had to use an echo statement to conditionally echo the form.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
  /* if the "submit" variable does not exist, the form has not been submitted - display initial page */
  if (!isset($_POST['submit'])) {
  ?&gt;
  
      &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
      Enter your age: &lt;input name="age" size="2"&gt;
      &lt;input type="submit" name="submit" value="Go"&gt;
      &lt;/form&gt;
  
  &lt;?php
      }
  else {
  /* if the "submit" variable exists, the form has been submitted - look for and process form data */
      // display result
      $age = $_POST['age'];
      if ($age &gt;= 21) {
          echo 'Come on in, we have alcohol and music awaiting you!';
          }
      else {
          echo 'You're too young for this club, come back when you're a little older';
      }
  }
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>