title: how to get the sum of the values of some arrays inside an array?
body: <p>How can I get the total deposit and total withdraw combined for each month? e.g (all January month total deposit and total withdraw) from an array.  </p>
  
  <p>Actually, I have some table (100+). Each table has so many records with deposit, withdraw and date column fields. I have to sum the deposit and withdraw value with grouped by date.  </p>
  
  <p>Indeed, I got the monthly total deposit and total withdraw amount for each table. Now, I have to sum each month from all tables. e.g, Total deposit and withdraw of Jaunuary of all tables.</p>
  
  <p>In my CI Controller:  </p>
  
  <pre><code>$all_table_id = $this-&gt;admin_model-&gt;get_all_id();
  
  foreach ($all_table_id as $table_id)
  {
      // $table_id['accountNo'] is generated table name 
      // e.g baby_ld_account_45456 ,baby_ld_account_12345
  
      $tableName = "baby_ld_account_" . $table_id['accountNo'];
  
      $single_table_monthly_data = $this-&gt;admin_model-&gt;get_monthly_data_each_table($tableName);
  
      // print_r($single_table_monthly_data);
  
      $all_table_monthly_data[] = $single_table_monthly_data;
  
      print_r($monthly_data);
  }
  </code></pre>
  
  <p>In my CI model:  </p>
  
  <pre><code>public function get_monthly_data_each_table($tableName) {
      $sql = "SELECT DATE_FORMAT(`entryDate`,'%M') as Month, 
                     SUM(`deposit`) AS `Deposit`, 
                     SUM(`withDraw`) AS `Withdraw` 
              FROM $tableName 
              WHERE YEAR(`entryDate`) = YEAR(CURDATE()) 
              GROUP BY DATE_FORMAT(`entryDate`,'%M')";
  
      $query = $this-&gt;db-&gt;query($sql);
      $result = $query-&gt;result_array($query);
  
      return $result;
  }
  </code></pre>
  
  <p>Array result:  </p>
  
  <pre><code>Array (
      [0] =&gt; Array ( 
          [0] =&gt; Array ( [Month] =&gt; January [Deposit] =&gt; 4000 [Withdraw] =&gt; 8000 )
          [1] =&gt; Array ( [Month] =&gt; February [Deposit] =&gt; 200 [Withdraw] =&gt; 5000 )
      )
  
      [1] =&gt; Array (
          [0] =&gt; Array ( [Month] =&gt; January [Deposit] =&gt; 1000 [Withdraw] =&gt; 1000 )
          [1] =&gt; Array ( [Month] =&gt; February [Deposit] =&gt; 3000 [Withdraw] =&gt; 6000 )
      )
      [2] =&gt; Array (
          [0] =&gt; Array ( [Month] =&gt; January [Deposit] =&gt; 6000 [Withdraw] =&gt; 2000 )
          [1] =&gt; Array ( [Month] =&gt; February [Deposit] =&gt; 4000 [Withdraw] =&gt; 8000 )
      )
  
      [3] =&gt; Array (
          [0] =&gt; Array ( [Month] =&gt; January [Deposit] =&gt; 3500 [Withdraw] =&gt; 2000 )
          [1] =&gt; Array ( [Month] =&gt; February [Deposit] =&gt; 1200 [Withdraw] =&gt; 5000 )
      )
  )
  </code></pre>
  
  <p>Can anyone give me a solution?  </p>