title: Array sum and count row in PHP
body: <p>I have a function getData that returns:</p>
  
  <pre><code>    array:4 [▼
    0 =&gt; array:1 [▼
      0 =&gt; "5689.01"
    ]
    1 =&gt; array:1 [▼
      0 =&gt; "5689.01"
  
    ]
    2 =&gt; array:1 [▼
      0 =&gt; "0.0"
    ]
    3 =&gt; array:1 [▼
      0 =&gt; "5665.11"
     ]
  ]
  </code></pre>
  
  <p>I need to COUNT number of rows (this time 4, as above) with values that are returned every time when I trigger a call and return total SUM of all results as listed.</p>
  
  <pre><code> $rows = $this-&gt;get('app')-&gt;getData();
  
   if($rows) {
          foreach ($rows as $row) {
              $sumOfAll = 0;
              $total = count($rows);
              $sumOfAll += array_sum(array($row[0] * $total));
  
              dump($sumOfAll);die;
      }
  }
  </code></pre>
  
  <p>I always get a wrong sum, in this case it was 22756.04.</p>