title: AJAX post to PHP, Calculate sum and return
body: <p>I got a table in html, I send a POST in ajax with 2 arrays, one called rowValues that contains 3 arrays, one for every row. And another array called columnValues that contains 3 arrays one for every column.</p>
  
  <p>I POST it ok, but the problem is :  How can I calculate in PHP the sum of every row and every column, and do an echo to success function showing the result in class "totalCol" and "total" of every column and row?</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;table id="sum_table"&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input value="0" class="sum1" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input value="0" class="sum2"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input value="0" class="sum3"/&gt;&lt;/td&gt;
          &lt;td class="total"&gt;0&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input value="0" class="sum1"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input value="0" class="sum2"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input value="0" class="sum3"/&gt;&lt;/td&gt;
          &lt;td class="total"&gt;0&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input value="0" class="sum1"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input value="0" class="sum2"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input value="0" class="sum3"/&gt;&lt;/td&gt;
          &lt;td class="total"&gt;0&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr class ="totalCol"&gt;
          &lt;td&gt;0&lt;/td&gt;
          &lt;td&gt;0&lt;/td&gt;
          &lt;td&gt;0&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;button id="tabla"&gt;+&lt;/button&gt;
  &lt;button id="moes"&gt;Hide/Show&lt;/button&gt;
  
  
  &lt;script&gt;
  
    $(document).on('change',function(){
  
       var columnValues={}, rowValues={};
  
       $("#sum_table tr").each(function(rowIndex){
            $("td input", $(this)).each(function(colIndex){
              var value=$(this).val();
              // indexes need +1 to get the row number, because 
              // the indexes are 0-based.
              if (undefined===columnValues[colIndex+1]){
                columnValues[colIndex+1]=[];
              }
              if (undefined===rowValues[rowIndex+1]){
                rowValues[rowIndex+1]=[];
              }
              rowValues[rowIndex+1].push(value);
              columnValues[colIndex+1].push(value);
  
            });
  
        });
              // send data to server
         $.ajax({
             url: 'suma.php',
             type: 'post',
             data: {rows:rowValues, columns:columnValues},
             dataType: 'json',
             success: function(data){
                 // insert your server-calculated data to dom   
  
             }
         }); 
  });
  </code></pre>
  
  <p>PHP CODE:</p>
  
  <p>
  
  <pre><code>foreach ($_POST['rows'] as $rowNumber =&gt; $values){
      // $values is an array with all the values in the row
      echo "Hola";
  }
  foreach ($_POST['columns'] as $columnNumber =&gt; $values){
      // $values is an array with all the values in the column
  }
  </code></pre>
  
  <p>Thank You in Advance Guys!</p>