title: How to sum up values inside a array variable?
body: <p>I have retrieved some values from database. In my view file I have the following:</p>
  
  <pre><code> $row['fee_amount']; 
  </code></pre>
  
  <p>Now, I want to sum up all the values inside  $row['fee_amount']; and then show it. </p>
  
  <p>I know I could sum up when querying the database, but I am interested to learn how to add using PHP . </p>
  
  <p>Would you please kindly teach me how to do it?</p>
  
  <h1>EDIT </h1>
  
  <pre><code>    &lt;?php if(count($records) &gt; 0) { ?&gt;              
          &lt;table id="table1" class="gtable sortable"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;                        
                      &lt;th&gt;S.N&lt;/th&gt;
                      &lt;th&gt;Fee Type&lt;/th&gt;
                      &lt;th&gt;Fee Amount&lt;/th&gt;                         
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;             
                  &lt;?php $i = 0; foreach ($records as $row){ $i++; ?&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;?php echo $i; ?&gt;.&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['fee_type'];?&gt;&lt;/td&gt;                                                
                          &lt;td&gt;&lt;?php echo $row['fee_amount'];?&gt;&lt;/td&gt;                                           
                      &lt;/tr&gt;                                                                                          
                  &lt;?php  } ?&gt;             
              &lt;/tbody&gt;                
              &lt;tr&gt;                                                        
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;Total&lt;/td&gt;
                  &lt;td&gt; 
                      I WANT TO DISPLAY THE SUMMATION RESULT HERE ADDING UP VALUES INSIDE THIS&gt;&gt;&gt; &lt;?  $row['fee_amount']; ?&gt; 
                  &lt;/td&gt;                                                                               
              &lt;/tr&gt;               
          &lt;/table&gt;
      &lt;?php } ?&gt;
  </code></pre>