title: PHP practice function ($result) can't be called
body: <p>I am doing PHP practice and I am stuck on this part.</p>
  <p>My problem is when I do simple math like 1+1 or 1/1 etc. The $result won't display. I am confused about which part of my code is causing the problem.   Please enlighten me on my mistakes</p>
  <p>Thank you.</p>
  <pre><code>       &lt;?php
           $first_num = $_POST['first_num'];
           $second_num = $_POST['second_num'];
           $operator = $_POST['operator'];
           $result = '';
  
           function cal_result($first_num,$second_num,$operator){
                if (is_numeric($first_num) &amp;&amp; is_numeric($second_num)) {
                      switch ($operator) {
                          case &quot;Add&quot;:
                          $result = $first_num + $second_num;
                          break;
                          case &quot;Subtract&quot;:
                          $result = $first_num - $second_num;
                          break;
                          case &quot;Multiply&quot;:
                          $result = $first_num * $second_num;
                          break;
                          case &quot;Divide&quot;:
                  $result = $first_num / $second_num;
                  }
              return $result;        
             }  
           }
        ?&gt;
  
      &lt;form action=&quot;simple_calculator.php&quot; method=&quot;post&quot; id=&quot;quiz-form&quot;&gt;
              &lt;p&gt;
                  &lt;input type=&quot;number&quot; name=&quot;first_num&quot; id=&quot;first_num&quot; required=&quot;required&quot; value=&quot;&lt;?php  cal_result($first_num,$second_num,$operator); ?&gt;&quot; /&gt; &lt;b&gt;First Number&lt;/b&gt;
              &lt;/p&gt;
              &lt;p&gt;
                  &lt;input type=&quot;number&quot; name=&quot;second_num&quot; id=&quot;second_num&quot; required=&quot;required&quot; value=&quot;&lt;?php cal_result($first_num,$second_num,$operator); ?&gt;&quot; /&gt; &lt;b&gt;Second Number&lt;/b&gt;
              &lt;/p&gt;
              &lt;p&gt;
                  &lt;input readonly=&quot;readonly&quot; name=&quot;result&quot; value=&quot;&lt;?php  echo $result; ?&gt;&quot;&gt; &lt;b&gt;Result&lt;/b&gt;
              &lt;/p&gt;
              &lt;input type=&quot;submit&quot; name=&quot;operator&quot; value=&quot;Add&quot; /&gt;
              &lt;input type=&quot;submit&quot; name=&quot;operator&quot; value=&quot;Subtract&quot; /&gt;
              &lt;input type=&quot;submit&quot; name=&quot;operator&quot; value=&quot;Multiply&quot; /&gt;
              &lt;input type=&quot;submit&quot; name=&quot;operator&quot; value=&quot;Divide&quot; /&gt;
      &lt;/form&gt;
  </code></pre>