<?php $arr = [6,4,9,3,8,2,1,5]; // Calculate the total of the array elements $sum = array_sum($arr); $len = count($arr); // Using integer division and modulo arithmetic calculate the average and remainder $avg = intdiv($sum,$len); $rem = $sum % $len; // Create a result array and fill with the average $result = array_fill(0,$len,$avg); // Spread the remainder over the first few elements. while($rem){$result[--$rem]++;} var_dump($result); ?>
You have javascript disabled. You will not be able to edit any code.