php 二维数组求平均值
Array//第一段([0]=>Array([id]=>30[cid]=>1[weight]=>55[pbf]=>6[measure_time]=>1411004598)...
Array //第一段
(
[0] => Array
(
[id] => 30
[cid] => 1
[weight] => 55
[pbf] => 6
[measure_time] => 1411004598
)
[1] => Array
(
[id] => 28
[cid] => 1
[weight] => 75
[pbf] => 6
[measure_time] => 1411004598
)
[2] => Array
(
[id] => 29
[cid] => 1
[weight] => 65
[pbf] => 6
[measure_time] => 1411004598
)
)
Array //第二段
(
[0] => Array
(
[id] => 23
[cid] => 1
[weight] => 72
[pbf] => 7
[measure_time] => 1410956776
)
[1] => Array
(
[id] => 25
[cid] => 1
[weight] => 70
[pbf] => 6
[measure_time] => 1410956776
)
)
以上数组我如何求得每段的二维数组weight的平均值 每段数组通过measure_time算weight的平均值 展开
(
[0] => Array
(
[id] => 30
[cid] => 1
[weight] => 55
[pbf] => 6
[measure_time] => 1411004598
)
[1] => Array
(
[id] => 28
[cid] => 1
[weight] => 75
[pbf] => 6
[measure_time] => 1411004598
)
[2] => Array
(
[id] => 29
[cid] => 1
[weight] => 65
[pbf] => 6
[measure_time] => 1411004598
)
)
Array //第二段
(
[0] => Array
(
[id] => 23
[cid] => 1
[weight] => 72
[pbf] => 7
[measure_time] => 1410956776
)
[1] => Array
(
[id] => 25
[cid] => 1
[weight] => 70
[pbf] => 6
[measure_time] => 1410956776
)
)
以上数组我如何求得每段的二维数组weight的平均值 每段数组通过measure_time算weight的平均值 展开
展开全部
第一段 weight的平均值
<?php
//$array 是你的第一段数组
$weight = 0;
$count = count($array);
foreach ($array as $key => $value) {
$weight+= $value['weight'];
}
echo $weight/$count;
?>
每段数组通过measure_time算weight的平均值
这句话不是很懂的意思
更多追问追答
追问
第一段和第二段数组是同时循环出来 第二段和第一段measure_time字段不同如何同时算第二段的值
追答
第一段和第二段数组是同时循环出来,数据结构三维数组么?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询