School project. You have 3 buckets that hold apples (they are arrays, dont ask why they are called apples. The buckts are arrays to, so they are arrays of arrays). They can only hold 15 each. You need to add more apples, but you first need to even out the buckets so that one doesn't over flow before any of the others.
<?php
$bucket[0]['apples'] = array(0,1,2,3,4,5,6,7); // 8 apples
$bucket[1]['apples'] = array(0,1,2,3,4,5,6,7,8); // 9 apples
$bucket[2]['apples'] = array(0,1,2,3); // 4 apples
// 21 total apples in 3 buckets, but not distributed evenly
// How can you even them out, such as?
$bucket[0]['apples'] = array(0,1,2,3,4,5,6); // 7 apples, 8 -1
$bucket[1]['apples'] = array(0,1,2,3,4,5,6); // 7 apples, 9 -2
$bucket[2]['apples'] = array(0,1,2,3,4,5,6); // 7 apples, 4 +3
// 21 total apples, evenly distributed
?>
I have to actually move the objects, since IRL the apples would would represent an array of values. I can tell it would take push() and pop(), but I can't wrap my brain around looping through it. Can anybody give me some clues?
Thanks