我有条件函数,它们的执行不是按照业务运行的,需要根据期望的结果进行转换。此函数包含排名和频率,它们是多维数组的一部分,它们基于某些计算执行求和我想根据排名位置添加频率,它们的执行部分运行不准确。你能帮我一下吗。<?php$arr = array ( 'AMXB 5321' => array( array("course_title_code" => "AMB 5321", "content" => "Course", "total" => "303", "count" => "85", "ranking" => array(array(5),array(2,4,5)), "frequency" => array(array(5),array(1,2,11))), array("course_title_code" => "AMB 5321", "content" => "Succeed in the course", "total" => "300", "count" => "85", "ranking" => array(array(3,5),array(3,4,5)), "frequency" => array(array(1,4),array(1,2,11)) ) ));array_walk($arr, function(&$v,$k){ foreach($v as $key => &$s){ $s['ranking'] = implode(',',range(1,5)); foreach($s['frequency'] as $key => &$value){ $temp = $value; $value = (count($value) == 5) ? $value : array_merge(array_fill(0, 5 - count($value), 0), $temp); if($key == 1){ for($i=0;$i<count($value);$i++){ $value[$i] += $s['frequency'][$key-1][$i]; } $temFormat = implode(',',$s['frequency'][1]); } } unset($s['frequency']); $s['frequency'] = $temFormat; }});echo "<pre>";print_r($arr);?>想要的结果Array( [AMXB 5321] => Array ( [0] => Array ( [course_title_code] => AMB 5321 [content] => Course [total] => 303 [count] => 85 [ranking] => 1,2,3,4,5 [frequency] => 0,1,0,2,16 ) ))
1 回答
- 1 回答
- 0 关注
- 162 浏览
添加回答
举报
0/150
提交
取消