Hi, I loop through an array looking at the date (as key) and if it is before the event date I use the rating value (as value). Basically I'm looking for the closest value in the array before the event date.
My code:
$ratingData = $player->ratingData;
foreach ($ratingData as $ratingDate => $ratingValue) {
list($year, $month, $day) = explode('-', $ratingDate);
$ratingTimestamp = mktime(0, 0, 0, $month, $day, $year);
if ($ratingTimestamp < $event->date) $ratingEvent = $ratingValue;
else break;
}
die('<p>rating used = ' . $ratingValue . ' from ' . $ratingDate .
' for eventdate ' . date('Y-m-d', $event->date) . '</p><p>ratingtimestamp = '.
$ratingTimestamp . ' vs eventdate = ' . $event->date);
My output:
rating used = 2467.9650092431 from 2005-01-17 for eventdate 2005-01-17
ratingtimestamp = 1105912800 vs eventdate = 1105912800
Clearly that is not right (if ($ratingTimestamp < $event->date))? Why is the smaller than not working?