3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array(1,1,2,1,4,5,7,2,3); asort($array); $total = array_sum($array); $array1 = array(); $array2 = array(); $array3 = array(); foreach($array as $number) { if(array_sum($array1) < $total / 3) { array_push($array1, $number); } elseif(array_sum($array2) < $total / 3) { array_push($array2, $number); } else { array_push($array3, $number); } } echo array_sum($array3); foreach($array1 as $number) { if(array_sum($array3) + $number == $total / 3) { array_push($array3, $number); } else { echo 'no'; } } print_r($array1); print_r($array2); print_r($array3);
based on tcCmm
Output for 5.3.19 - 7.2.0
7nonononononoArray ( [0] => 1 [1] => 1 [2] => 1 [3] => 2 [4] => 2 [5] => 3 ) Array ( [0] => 4 [1] => 5 ) Array ( [0] => 7 )