title: Stack array losing previous values for single page submission
body: <p>I'm trying to do the push-and-pop stack array in PHP but only the last value is stored. How can I store the other values as well even if I click on the button again &amp; load the same page?
  This is what I've done:</p>
  
  <pre><code>&lt;?php
      if(!$_GET)
          $myStack = array();
      else
          $myStack[] = "";
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt; &lt;title&gt;Exercise&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="test.php" method="get"&gt;
          Element: &lt;input type="text" name="num"  value="0"/&gt;&lt;br/&gt;
          &lt;input type="submit" name="push" value="push" /&gt;
          &lt;input type="submit" name="pop" value="pop" /&gt;
      &lt;/form&gt;
  
  &lt;?php
  
      if(isset($_GET["push"])){
          array_push($myStack, $_GET["num"]);
          foreach($myStack as $val)
              echo $val . " ";
      }
      elseif(isset($_GET["pop"])){
          array_pop($myStack);
          foreach($myStack as $val)
              echo $val . " ";
      }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>