title: Make PHP Calculator Store and Display History
body: <p>I am new to PHP and I am trying to create a simple calculator that also displays the history (past calculations) in a div on the page. </p>
  
  <p>You input something like "4+" in the first field and "3" in the second, and it displays "4+3=7" in the div called "results". However, I want to display the whole history of results there, so when I perform a new calculation, both calculations/results will be displayed the results div. What's the best way of doing this in PHP? Would <code>DOMNode::appendChild</code> be an option?</p>
  
  <p>Here is my code this far: </p>
  
  <pre><code>&lt;div id="form"&gt;
      &lt;form action="" method="post"&gt;
          &lt;input type ="text" name="firstNumber"&gt;
          &lt;input type ="text" name="secondNumber"&gt;
          &lt;input type ="submit" style="display:none"&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  
  Result:
  
  &lt;?php 
  
      $number1 = $_POST["firstNumber"];
      $number2 = (int)$_POST["secondNumber"];
  
      @$operator = substr($number1, -1);
  
  
  switch($operator){
      case '+':
          $result = (int)$number1+$number2;
          echo $result;
          break;
       case '-':
          $result = (int)$number1-$number2;
          echo $result;
          break;
      case '*':
          $result = (int)$number1*$number2;
          echo $result;
          break;
      case '/':
          $result = (int)$number1/$number2;
          echo $result;
          break;
  }
  
  ?&gt;
  
  
  &lt;div id="results"&gt;
      &lt;?php echo substr($number1,0, -1);
          echo $operator; 
          echo $number2; ?&gt;
   &lt;br&gt;=
      &lt;?php echo $result; ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thank you for helping out! </p>