3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates = array("2012-06-11 08:30:49", "2012-06-07 08:03:54", "2012-05-26 23:04:04", "2012-05-27 08:30:00", "2012-06-08 08:30:55", "2012-06-12 07:45:45"); $children = array("callum" => "1028", "daniel" => "1029"); $closeDate = array(); $firstDate = strtotime("2012-05-29 07:45:45"); function returnClosestDate($firstTime, $dates, $closeDate, $child){ global $initialLoop; foreach ($dates as $key => $date) { $dateToCompare = strtotime($date); $diff = $firstTime - $dateToCompare; if ($diff < 0) $diff *= -1; if (count($closeDate) == 0) { $closeDate[] = array("date" => $date, "diff" => $diff); continue; } print_r($closeDate); if(!alreadyExistInArray($closeDate, $date)){ if ($diff < $closeDate) { $closeDate[] = array("date" => $date, "diff" => $diff); } } } exit; } function alreadyExistInArray($closeDate, $date){ foreach($closeDate as $key => $close){ print_r($key[$close]); exit; if($close["date"] === $date) return true; } } foreach($children as $key => $child){ returnClosestDate($firstDate, $dates, $closeDate, $child); }

preferences:
83.91 ms | 402 KiB | 5 Q