3v4l.org

run code in 500+ PHP versions simultaneously
<?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); ?>
Output for git.master, git.master_jit, rfc.property-hooks
array(8) { [0]=> int(5) [1]=> int(5) [2]=> int(5) [3]=> int(5) [4]=> int(5) [5]=> int(5) [6]=> int(4) [7]=> int(4) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.52 ms | 1273 KiB | 4 Q