我需要检查一个特定的日期是否已通过,如果已通过,则将根据日期数组检查哪个日期最接近。
我已经开始了,但是
编码:
<?php
function getCurrDate ($c_id){
// Fetch the course date
$course_nxt_date = "2013-02-03";
// fetch current date
$today = date("Y-m-d");
// Check if course date is in the future
if($course_nxt_date > $today){
$course_date = $course_nxt_date;
return $course_date;
}
// Check if course date is exactly today
elseif($course_nxt_date == $today){
$course_date = $course_nxt_date;
return $course_date;
}
// Check if course date is passed
else{
// Since course date is passed, get an array of future dates from database
$all_course_dates_query = @mysql_query("select * from pub_calendar_dates where course_id = '$c_id' order by course_date asc");
//Loop through the array
$all_course_dates_arr = array();
while ($all_course_dates_row = @mysql_fetch_assoc($all_course_dates_query)){
// assign each variable in the $all_course_dates_row to a new array $all_course_dates_arr
$all_course_dates_arr[] = $all_course_dates_row['course_date'];
}
// This is where I became blank on what to do next and Im stucked...Need help from here
return $course_date;
}
}
?>
更多细节:
如果 $course_nxt_date 已通过,则将针对同一课程、特定数据库表中某处的某些现有未来日期进行检查。在对照数组 $all_course_dates_arr[] 检查 $course_nxt_date 时,我需要获取最接近 $course_nxt_date 的日期
Example of dates that could be in the array - $all_course_dates_arr[]:
$all_course_dates_arr[0] = "2013-01-25";
$all_course_dates_arr[1] = "2013-04-08";
$all_course_dates_arr[2] = "2013-06-13";
$all_course_dates_arr[3] = "2013-08-03";
$all_course_dates_arr[4] = "2013-02-17";
自从
$course_nxt_date = "2013-02-03";
该函数应输出最近的日期,如下所示:
echo getCurrDate(18);
Output - 2013-02-17
我会很高兴得到这方面的帮助...谢谢!