Evenly Distribute items in a bucket( or having a property ) to another bucket(or array) following property ...
I have an array like
Array
(
[type1] => Array
(
[0] => 1,
[1] => 2,
[2] => 3,
[3] => 4
)
[type2] => Array
(
[0] => 5,
[1] => 6,
[2] => 7,
[3] => 8
)
[type3] => Array
(
[0] => 9,
[1] => 10,
[2] => 11,
[3] => 12
)
[type4] => Array
(
[0] => 13,
[1] => 14,
[2] => 15,
[3] => 16
)
)
SO i need to sort it into an array such that each element of this new array will have all the types of elements equally distributed to each of the elements of new array
What i Need
array(
[0]=>array(1,5,9,13)
[1]=>array(2,6,10,14)
[2]=>array(3,7,11,15)
[3]=>array(4,8,12,16)
)
The issue here is the first array's sub-arrays may have varying no of elements
A simpler version: Imagine u have a set of horses from different countries How do you organize a "n" ( here 4 ) number of different races so that in all the races the country of the horse present is as evenly distributed as possible
In Db its something like
regid nation race1
1 country1 1
2 country2 1
3 country3 0
4 country1 1
5 country1 1
where regid is id no for each participant and race1 is to denote if its participating in that race or not