我不确定如何以最好的方式解释我想做的事情。但我要试一试!我有一个这样的数组:
$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
)
);
注意:数组会更大,并且值不会只是那些(但总是会是整数)。
如何将这个数组分成两半,每个部分都有来自每个不同键的相似平均值(key1 的平均值相似,key2 的平均值相似,key3 的平均值相似)?
在上面的例子中,结果应该是:
$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
)
);
(两个数组的 key1 的平均值为 2.5,key2 的平均值为 3.5,key3 的平均值为 2)