Working on a small formula to find the closet date from a number of dates stored in an array. I can get this working with hardcoded dates, but not using PHP Variables, any ideas?
<?php
$dates = array
(
'0'=> date('Y-m-d', $Date1),
'1'=> date('Y-m-d', $Date2),
'2'=> date('Y-m-d', $Date3),
'3'=> date('Y-m-d', $Date4),
'4'=> date('Y-m-d', $Date5),
'5'=> date('Y-m-d', $Date6),
'6'=> date('Y-m-d', $Date7),
'7'=> date('Y-m-d', $Date8)
);
function closes($dates, $findate)
{
$newDates = array();
foreach($dates as $date)
{
$newDates[] = strtotime($date);
}
sort($newDates);
foreach ($newDates as $a)
{
if ($a >= strtotime($findate)) return $a;
}
return end($newDates);
}
$values = closes($dates, date('Y-m-d'));
?>
<h3>Next Date</h3><br/>
<?php echo date('l, F jS, Y',$values);
}?>