title: How to make a sum of array values
body: <p>I have an array and I iterate through its first 7 values with this function:</p>
  
  <pre><code>function clicksLast7Days($data)
          {
              $path = $data-&gt;data-&gt;data-&gt;clicks;
              $num_loops = 0;
              foreach ($path as $key =&gt; $item){
                  $num_loops++;
                  if($num_loops &gt; 7) break;
                  if ($key &gt;= 0) {
                  $array[] = $item-&gt;clicks;
                  }     
              }
             return json_encode($array);   
          }
  </code></pre>
  
  <p>The array's structure (if it helps) is:</p>
  
  <pre><code>["data"]=&gt;
    object(stdClass)#212 (3) {
      ["status_code"]=&gt;
      int(200)
      ["data"]=&gt;
      object(stdClass)#211 (3) {
        ["days"]=&gt;
        int(30)
        ["total_clicks"]=&gt;
        int(6)
        ["clicks"]=&gt;
        array(30) {
          [0]=&gt;
          object(stdClass)#215 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1466395200)
          }
          [1]=&gt;
          object(stdClass)#216 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1466308800)
          }
          [2]=&gt;
          object(stdClass)#217 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1466222400)
          }
          [3]=&gt;
          object(stdClass)#218 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1466136000)
          }
          [4]=&gt;
          object(stdClass)#219 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1466049600)
          }
          [5]=&gt;
          object(stdClass)#220 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1465963200)
          }
          [6]=&gt;
          object(stdClass)#221 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1465876800)
          }
          [7]=&gt;
          object(stdClass)#222 (2) {
            ["clicks"]=&gt;
            int(0)
            ["day_start"]=&gt;
            int(1465790400)
          }
  </code></pre>
  
  <p>The problem is that by using my function I get an array of elements: 
  [0,0,0,0,0,0,0]. But what I want is to obtain their sum (which in this case is 0), and not an array, just a number.</p>