title: PHP: How to get sum of elements of 2 dimension array?
body: <p>I want to get total of elements of each row at the end of that row and total of elements of each column at the end of each column.</p>
  
  <p><strong>For Example:</strong></p>
  
  <p><strong>I have an array with digits values like this:</strong></p>
  
  <pre><code>$twoDimArr = array(  array("1" , "2" , "3" , "4"),
                       array("1" , "2" , "3" , "4"),
                       array("1" , "2" , "3" , "4"),
                       array("1" , "2" , "3" , "4"),
                       array("1" , "2" , "3" , "4"),
                       array("1" , "2" , "3" , "4"),
                       array("1" , "2" , "3" , "4")
  
  );
  </code></pre>
  
  <p><strong>output something like this:</strong></p>
  
  <pre><code>$twoDimArr = array(  array("1" , "2" , "3" , "4", "total" =&gt; "10"),
                       array("1" , "2" , "3" , "4", "total" =&gt; "10"),
                       array("1" , "2" , "3" , "4", "total" =&gt; "10"),
                       array("1" , "2" , "3" , "4", "total" =&gt; "10"),
                       array("1" , "2" , "3" , "4", "total" =&gt; "10"),
                       array("1" , "2" , "3" , "4", "total" =&gt; "10"),
                       array("1" , "2" , "3" , "4", "total" =&gt; "10"))
                       "columnTotal =&gt; "array("7" , "14" , "21" , "28", "70")
  
      );
  </code></pre>
  
  <p><strong>Input Array:</strong> 
  No of elements in rows may vary but no of each row element will be equal to other rows elements. indexes in input array may be anything.</p>
  
  <p>I have coded this and it is working for me but I am not happy with the amount of code. May be someone will code more efficient and less code solution. </p>
  
  <p>Thanks</p>