I'm not sure how the best way to explain what I want to do. But I'm gonna give it a try! I've have an array like this:
$array = array(
"a" => array(
"key1" => 3,
"key2" => 4,
"key3" => 1
),
"b" => array(
"key1" => 4,
"key2" => 5,
"key3" => 2
),
"c" => array(
"key1" => 2,
"key2" => 3,
"key3" => 3
),
"d" => array(
"key1" => 1,
"key2" => 2,
"key3" => 2
)
);
Note: the array will be much larger and the values are not going to be only those (but the are always going to be an integer).
How can I split this array in half having at each part a similar average value from each different key (a similar average value for key1, similar average value for key2 and similar average value for key3)?
In the above example, the result should be:
$array[0] = array(
"a" => array(
"key1" => 3,
"key2" => 4,
"key3" => 1
),
"c" => array(
"key1" => 2,
"key2" => 3,
"key3" => 3
)
);
$array[1] = array(
"b" => array(
"key1" => 4,
"key2" => 5,
"key3" => 2
),
"d" => array(
"key1" => 1,
"key2" => 2,
"key3" => 2
)
);
(Both array have an average of 2.5 value for key1, 3.5 for key2 and of 2 for key3)