title: How to calculate the element of the array?
body: <p>I have an array like the following </p>
  
  <pre><code> $array = array(1,2,4,7,1,6,2,8);
  </code></pre>
  
  <p>I want to divide the array to 3 groups and the sum of the each group will need to be as equal as possible.</p>
  
  <p>so the result is</p>
  
  <pre><code>8,2    = 10
  7,2,1  = 10
  6,4,1  = 11
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>$array = array(1,2,4,7,1,6,2,8);   
     $total = array_sum($array);
     $setNumber = $total/3;
  
     for($i; $i&lt;count($array); $i++){
         $group += $array[$i]
          if($group &gt; $setNumber){
             break;
          }
     }
  </code></pre>
  
  <p>I am not sure how to complete this task. Can anyone help me about it? Thanks!</p>