有一个这样的数组(是按总分排好名的) 里面有两个学校混合的学生成绩 按照总分排名已经排出来了,但是我还想要每个学生在自己的学校所在排名这个怎么去写a1、a2、、是各科成绩
Array
(
[0] => Array
(
[id] => 72
[nianji] => 高三
[name] => 学生LL
[kaohao] => 100024
[number] => 0024
[school] => 云校
[banji] => 4
[a1] => 150
[a2] => 100
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 80
[addtime] => 2023-06-14 14:40:01
[zongfen] => 330
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 330
[cjdeep] => 1
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 1
)
[1] => Array
(
[id] => 49
[nianji] => 高三
[name] => 学生A
[kaohao] => 100001
[number] => 0001
[school] => 云校
[banji] => 11
[a1] => 140
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 300
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 300
[cjdeep] => 2
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 2
)
[2] => Array
(
[id] => 50
[nianji] => 高三
[name] => 学生B
[kaohao] => 100002
[number] => 0002
[school] => 云校
[banji] => 1
[a1] => 135
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 295
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 295
[cjdeep] => 3
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 3
)
[3] => Array
(
[id] => 51
[nianji] => 高三
[name] => 学生C
[kaohao] => 100003
[number] => 0003
[school] => 云校
[banji] => 3
[a1] => 130
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 290
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 290
[cjdeep] => 4
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 4
)
[4] => Array
(
[id] => 52
[nianji] => 高三
[name] => 学生D
[kaohao] => 100004
[number] => 0004
[school] => 云校云校
[banji] => 5
[a1] => 125
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 285
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 285
[cjdeep] => 5
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 5
)
[5] => Array
(
[id] => 56
[nianji] => 高三
[name] => 学生H
[kaohao] => 100008
[number] => 0008
[school] => 云校
[banji] => 1
[a1] => 105
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 265
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 265
[cjdeep] => 6
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 6
)
[6] => Array
(
[id] => 57
[nianji] => 高三
[name] => 学生I
[kaohao] => 100009
[number] => 0009
[school] => 云校云校
[banji] => 6
[a1] => 100
[a2] => 100
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 60
[addtime] => 2023-06-14 14:40:01
[zongfen] => 260
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 260
[cjdeep] => 7
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 7
)
[7] => Array
(
[id] => 53
[nianji] => 高三
[name] => 学生E
[kaohao] => 100005
[number] => 0005
[school] => 云校
[banji] => 1
[a1] => 120
[a2] => 80
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 53
[addtime] => 2023-06-14 14:40:01
[zongfen] => 253
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 253
[cjdeep] => 8
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 8
)
[8] => Array
(
[id] => 59
[nianji] => 高三
[name] => 学生K
[kaohao] => 100011
[number] => 0011
[school] => 云校
[banji] => 8
[a1] => 90
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 250
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 250
[cjdeep] => 9
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 9
)
[9] => Array
(
[id] => 62
[nianji] => 高三
[name] => 学生BB
[kaohao] => 100014
[number] => 0014
[school] => 云校云校
[banji] => 1
[a1] => 75
[a2] => 95
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 240
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 240
[cjdeep] => 10
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 10
)
[10] => Array
(
[id] => 63
[nianji] => 高三
[name] => 学生CC
[kaohao] => 100015
[number] => 0015
[school] => 云校
[banji] => 9
[a1] => 70
[a2] => 90
[a3] => 0
[a4] => 0
[a5] => 0
[a6] => 0
[a7] => 0
[a8] => 0
[a9] => 0
[a10] => 0
[a11] => 0
[a12] => 70
[addtime] => 2023-06-14 14:40:01
[zongfen] => 230
[kemu] => Array
(
[0] => Array
(
[id] => 7
[name] => 总分
[zongfen] => 330
[cjsum] => 230
[cjdeep] => 11
[xchool] => 0
[xbanji] => 0
)
[1] => Array
(
[id] => 3
[name] => 外语
[zongfen] => 80
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[2] => Array
(
[id] => 2
[name] => 数学
[zongfen] => 100
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
[3] => Array
(
[id] => 1
[name] => 语文
[zongfen] => 150
[cjsum] => 0
[cjdeep] => 0
[xchool] => 0
[xbanji] => 0
)
)
[deep] => 11
)
想要每个学生在自己的学校所在排名这个怎么去写
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 红色荷包蛋 2023-06-19 11:25关注
答案参考ChapGPT Plus . 希望对你有帮助根据您提供的数组,每个学生的在自己学校所在排名可以通过以下方式计算:
首先,您需要按学校和总分对数组进行分组和排序,以获得每个学校按总分排好序的学生列表。
接下来,您可以遍历每个学生,在其所属学校的学生列表中查找其自己的排名。
以下是一个示例的PHP代码,展示了如何实现上述步骤:
// 原始数组 $students = array( array( 'id' => 72, 'name' => '学生LL', 'school' => '云校', 'zongfen' => 330, ), array( 'id' => 49, 'name' => '学生A', 'school' => '云校', 'zongfen' => 300, ), array( 'id' => 50, 'name' => '学生B', 'school' => '云校', 'zongfen' => 295, ), // 其他学生... ); // 按学校和总分排序 usort($students, function ($a, $b) { if ($a['school'] !== $b['school']) { return strcmp($a['school'], $b['school']); } return $b['zongfen'] - $a['zongfen']; }); // 计算每个学生在自己学校所在排名 $rankings = array(); $currentRank = 1; $currentSchool = $students[0]['school']; foreach ($students as $student) { if ($student['school'] !== $currentSchool) { $currentRank = 1; $currentSchool = $student['school']; } $rankings[$student['id']] = $currentRank; $currentRank++; } // 输出每个学生的在自己学校所在排名 foreach ($rankings as $studentId => $rank) { echo "学生ID: $studentId, 学校内排名: $rank\n"; }
请注意,上述代码仅展示了计算每个学生在自己学校所在排名的基本逻辑,并假设了已知的数组结构。您可以根据实际情况进行适当的调整和修改。
解决 1无用
悬赏问题
- ¥15 在虚拟机中安装flash code
- ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
- ¥20 verilog状态机方法流水灯
- ¥15 pandas代码实现不了意图
- ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
- ¥25 LT码在高斯信道下的误码率仿真
- ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
- ¥15 yolov5目标检测并显示目标出现的时间或视频帧
- ¥15 电视版的优酷可以设置电影连续播放吗?
- ¥50 复现论文;matlab代码编写