php, difference between multiple dates -
i have multiple dates example: 1395637200 1402894800 1403499600
what want them checking 1 of them is: a. "previous" date b. "next" date how can in php lot of them (±100-500)?
try this:
// current array of dates $dates = array(1395637200, 1402894800, 1403499600); // add together current date array , store in $cur $dates[] = $cur = time(); // sort dates (with current date added) sort($dates); // key of current date $today = array_search($cur, $dates); // if current date first in array, there no previous date. // otherwise, date previous key $prev = $today == 0 ? null : $dates[$today-1]; // if current date lastly in array, there no next date. // otherwise date next key $next = $today == count($dates)-1 ? null : $dates[$today+1]; see demo
php date difference
No comments:
Post a Comment