Php 从记录数组中获取字段

Php 从记录数组中获取字段,php,arrays,field,average,Php,Arrays,Field,Average,如何从数组中记录的字段中获取所有值 我想从数组中特定字段下的数字分数中求平均值。数组是从窗体中提取的。这是我到目前为止所做的,但它就是不起作用 $records = get_field('maths_month_report'); //gets all the records $progressscore = $records['progress']; //targets the specific field in those records echo . array_sum($progress

如何从数组中记录的字段中获取所有值

我想从数组中特定字段下的数字分数中求平均值。数组是从窗体中提取的。这是我到目前为止所做的,但它就是不起作用

$records = get_field('maths_month_report'); //gets all the records
$progressscore = $records['progress']; //targets the specific field in those records
echo . array_sum($progressscore)/count($progressscore) .; //divides the numbers in the field by the amount of records
修订:我很抱歉没有提到这些记录是“数学月报告”数组中的数组。我可以针对特定记录中的特定字段使用:

$firstrecord = $records[0];
$output = $firstrecord['progress']; 

我只想将所有“进度”值作为目标,以便对其进行平均。

根据您的评论,如果这些是数组中的数组,则需要构建一个新数组:

$progresscore = array_column($records, 'progress')
PHP<5.5:

$progresscore = array_map(function($item) {
    return $item['progress'];
}, $records);
或者,只需迭代您自己:

$sum = $count = 0;
foreach ($records as $record) {
    $sum += $record['progress'];
    ++$count;
}
echo $sum / $count;

你目前的尝试到底有多失败?请您详细说明一下,例如,原点阵列的结构(使用
print\r
的输出)为什么回波后有两个点?这不是必需的。使用var_dump($progressscore);告诉我们数组包含什么?它是什么意思“不工作”?$progressscore到底包含什么?echo中的这些点是干什么用的?get_字段不是php函数,而是您自己的?wordpress?最终结果被回传到HTMLSo,我现在应该有:$records=get_field('mathematics_month_report')$progressscore=explode(“,”,$records['progress'])$进度=数组总和($progressscore)/计数($progressscore);它是一个多维数组。记录是数组中的数组。我只需要瞄准那些领域Arrays@user1721230更新。这完全做到了!!!呜呼!!!非常感谢您在“echo$sum/count”中的发言;count少了一美元……我在一堵完整的砖墙前。非常感谢你的帮助