PHP Sum Array - sum only elemants of an array
<p>I have have an array as follows:</p>

<p><code>$row</code> when I output the entire array it produces the following:  </p>

<p><code>1.  I like crisps (38)     37% 55% 8%  0%</code></p>

<p>When I <code>echo</code> one part of the array I get the 4 figures I am interested in.</p>

<p><code>echo "&lt;td class='set1'&gt;". number_format($row[6], 0) ."%&lt;/td&gt;";</code></p>

<p>The above code outputs the following 4 numbers: </p>

<p>37% 55% 8%  0% </p>

<p>What I would like to do is simply ad the first two numbers together (i.e. 37% + 55%) and output the result (92%). Hope that helps? </p>

<p>I should also point out that the array contains much more information than just these four figures.</p>

<p>As requested: output from <code>var_dump[6]</code></p>

<p><code>string(7) "36.8421" string(7) "28.9474" string(7) "39.4737" string(7) "23.6842" string(7) "28.9474" string(6) "8.0000" string(7) "23.6842" string(7) "39.4737" string(7) "11.1111" string(7) "13.8889" string(7) "11.1111" string(7) "13.8889" string(7) "17.1429" string(7) "20.0000" string(7) "28.5714" string(7) "25.7143" string(7) "34.2857" string(7) "28.5714" string(7) "28.5714" string(7) "28.5714" string(7) "20.5882" string(7) "20.5882" string(7) "11.7647" string(7) "29.4118" string(7) "17.6471" string(7) "20.5882" string(6) "3.0303" string(6) "2.9412" string(6) "3.0303" string(7) "38.2353" string(7) "12.1212" string(7) "27.2727" string(7) "18.1818" string(7) "33.3333" string(7) "34.7826" string(7) "17.3913" string(7) "30.4348" string(7) "17.3913" string(7) "17.3913" string(7) "13.0435" string(7) "30.4348" string(7) "27.2727"</code></p>

<p>Is there any way to do this?</p>

<p>Thanks in advance,</p>

<p>Homer.</p>

<p>Entire code - hope this helps:</p>

<pre><code>if ($mysqli-&gt;multi_query($query)) {
do {
    /* store first result set */
    if ($result = $mysqli-&gt;store_result()) {
        $i = 1;
        while ($row = $result-&gt;fetch_row()) {
            if($i==1){
            echo "&lt;tr&gt;&lt;td class='qnum'&gt;&lt;span class='bold'&gt;". $row[3] .".&lt;/span&gt;&lt;/td&gt;&lt;td class='qtext'&gt; ". $row[4] ." (&lt;span class='italics'&gt;". $row[5] ."&lt;/span&gt;)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;";
            $i = 0;
            }

            echo "&lt;td class='set1'&gt;". number_format($row[6], 0) ."%&lt;/td&gt;";
            $var =  $row[6];
        }
        echo "&lt;/tr&gt;";
        $result-&gt;free();
    }
    /* print divider */
    //if ($mysqli-&gt;more_results()) {
      //  printf("-----------------\n");
    //}
} while ($mysqli-&gt;next_result());
}
</code></pre>

<p>The section where $row[6] appears is where the four firgures 37%    55% 8%  0% appear - I would like to add the first two of these figures together.</p>

<p>If this helps, here's the result of the SQL query</p>

<pre><code>response    q1  Responses   qnum    Question_Text   Total   percentage
4           4   14          1       I like crisps   38    36.8421
3           3   21          1       I like crisps   38    55.2632
2           2   3           1       I like crisps   38    7.8947
1           NULL    0       1       I like crisps   38    0.0000
</code></pre>

<p>The what I'd like to do is ad the 36.8421 and 55.2632 together.</p>

<p>Hope this helps!</p>
