Home>Article>Backend Development> How to implement statistical data merging in PHP

How to implement statistical data merging in PHP

little bottle
little bottle forward
2019-04-25 13:55:04 3363browse

This article mainly talks about using PHP to integrate different statistical results. As shown in the figure, the number of people in different grade levels is counted according to grade (this is just an example), and then a method is written to process these statistics. Array, interested friends can check it out, I hope it will be helpful to you.

 $item) { $_arr_key = $_modal_key; $_arr_key[$key_column] = $item; foreach ($_list_arr as $_arr) {//遍历需合并数据结果 foreach ($_arr as $em) { if ($item == $em[$key_column]) { foreach ($_list_column as $_column) { //统计结果大于0,更新相应统计字段数据(判断数组内容是否存在) if ($em[$_column] > 0) $_arr_key[$_column] = $em[$_column]; } } } } $_return_data[$key] = $_arr_key; unset($_arr_key); } return $_return_data; } $score_a = array( array('grade' => '一年级', 'sum_a' => 20), array('grade' => '二年级', 'sum_a' => 21), array('grade' => '三年级', 'sum_a' => 15), array('grade' => '四年级', 'sum_a' => 3), array('grade' => '五年级', 'sum_a' => 14) ); $score_b = array( array('grade' => '一年级', 'sum_b' => 21), array('grade' => '二年级', 'sum_b' => 14), array('grade' => '四年级', 'sum_b' => 40), array('grade' => '五年级', 'sum_b' => 12), array('grade' => '六年级', 'sum_b' => 25), ); $score_c = array( array('grade' => '一年级', 'sum_c' => 45), array('grade' => '三年级', 'sum_c' => 24), array('grade' => '四年级', 'sum_c' => 5), array('grade' => '六年级', 'sum_c' => 12) ); $score_d = array( array('grade' => '一年级', 'sum_d' => 12), array('grade' => '二年级', 'sum_d' => 45), array('grade' => '六年级', 'sum_d' => 12) ); $_last_data = statArrMergeHandle('grade', array('sum_a', 'sum_b', 'sum_c', 'sum_d'), $score_a, $score_b, $score_c, $score_d);

Final result:

Related tutorials:PHP video tutorial

The above is the detailed content of How to implement statistical data merging in PHP. For more information, please follow other related articles on the PHP Chinese website!

php
Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete