我想初始化一个关联数组,其中键是一个日期,值是布尔值,1表示在课堂上参加,0表示不在。由于某种原因,有一个日期初始化为1而不是0,我无法弄清楚原因。
这是循环:
runTask(["/path/to/script", "scriptarg", "another argument"])
目前有两位学生在数据库中。
身份= 5的学生的foreach ($students_list as $key => $student) {
$student_id = $student['student'];
$student_presence_arr = $presence_arr[$student_id]; //array of registration dates for each student
$student_name = $student["first_name"]." ".$student["last_name"];
foreach ($student_presence_arr as $key=> $attended) { //loop over each date student attended and set to 1 = attended
$date = strtok($attended['date'], " ");
$date_arr[$date] = 1;
}
$table .= '<tr><td>'.$student_name.'</td>';
foreach ($date_arr as $date => $status) {
if($date < date("Y-m-d")){
$status == 1 ? $table .= '<td><span class="glyphicon glyphicon-ok"></span></td>' : $table .= '<td><span class="glyphicon glyphicon-remove"></span></td>';
}
else{
$table .= "<td></td>";
}
}
$table .= '</tr>';
}
var_dump
是:
presence_arr
对于id = 1的学生是这样的:
{ [5]=> array(5) {
[0]=> array(4) { ["student"]=> string(1) "5" ["date"]=> string(19) "2016-02-14 00:00:00" }
[1]=> array(4) { ["student"]=> string(1) "5" ["date"]=> string(19) "2016-02-28 00:00:00" }
[2]=> array(4) { ["student"]=> string(1) "5" ["date"]=> string(19) "2016-03-27 00:00:00"}
[3]=> array(4) { ["student"]=> string(1) "5" ["date"]=> string(19) "2016-01-03 05:00:00" }
[4]=> array(4) { ["student"]=> string(1) "5" ["date"]=> string(19) "2016-01-10 09:00:00" }
}
但正如你在图片中看到的那样..
由于某种原因,两个学生的日期01-17都标有✓但是如果id = 5的学生应该 X 。知道我在这里缺少什么吗? THX
更新:
[1]=> array(1) {
[0]=> array(4) { ["student"]=> string(1) "1" ["date"]=> string(19) "2016-01-17 00:00:00"
} }
:
print_r($date_arr)