试图将学期、班级、学生的 3 层数组组合在一起,形成候补名单清算页面。这是我用来创建数组的 foreach,但有些地方不对劲。生成的数组不适合循环并制作学期 > 课程 > 学生的 html 表。我的 foreach 看起来像这样
foreach ($active_terms as $term) {
$waitlists[ $term['term_id'] ] = $term;
foreach ($active_courses as $course) {
if ( ($course['term_id'] == $term['term_id']) && ($course['students_waitlisted'] > 0) ) {
$waitlists[ $term['term_id'] ][ $course['course_id'] ] = $course;
foreach ($waitlisted_reservations as $reservation) {
if ( ($term['term_id'] == $reservation['term_id'])
&& ($course['course_id'] == $reservation['course_id']) ) {
$waitlists[ $term['term_id'] ][ $course['course_id'] ][ $reservation['reservation_id'] ] = $reservation;
}
}
}
}
}
结果数组很接近,但看起来像这样:
Array
(
[1] => Array
(
[term_id] => 1
[term_title] => Summer Session 1
[term_begin_date] => June 25 2012
[3] => Array
(
[term_id] => 1
[course_id] => 3
[course_title] => Biology 1
[course_student_limit] => 8
[students_reserved] => 6
[students_registered] => 0
[students_waitlisted] => 3
[175] => Array
(
[term_id] => 1
[course_id] => 3
[reservation_id] => 175
[reservation_grade_level] => 12
[student_sis_id] => 289055
)
[173] => Array
(
[term_id] => 1
[course_id] => 3
[reservation_id] => 173
[reservation_grade_level] => 08
[student_sis_id] => 111988
)
)
)
[2] => Array
(
[term_id] => 2
[application_id] => 2
[term_title] => Summer Session 2
[term_begin_date] => July 23 2012
[18] => Array
( ....
有人可以指出我如何正确地制作亲子巢吗?或者这个数组是否正确,我搞砸了如何使用嵌套的 foreach 来构建表格?