我有通道的陣列,到目前爲止,我懂得回報的最大值和最小值是這樣的:PHP從數組中查找中值並返回鍵和值?
// clear from any empty channels
$channels = array_filter($scan['channels']);
// get min/max values
$min = array_keys($channels, min($channels));
$max = array_keys($channels, max($channels));
// this returns the channel name wich is what I need
到目前爲止,我想獲得中位數鍵(頻道)的名字,我怎麼能做到這一點?
// this is the array of channels
Array
(
[chann_1] => 155.755
[chann_2] => 154.61
[chann_3] => 156.719
[chann_4] => 156.727
[chann_5] => 155.797
[chann_6] => 157.615
[chann_7] => 154.257
[chann_8] => 151.724
[chann_9] => 156.549
[chann_10] => 156.594
[chann_11] => 157.56
[chann_12] => 156.405
)
你希望所有的值儀式的平均值?如果是做array_sum($頻道)/計數($頻道) –
上帝,平均是一樣的中位數,哈哈,讓我試試 –
但我不需要的價值,但關鍵(頻道)名稱,任何想法? –