@ 2016-11-08T11:39:57Z <?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);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 Array
(
[date] => 2012-06-11 08:30:49
[diff] => 1125904
)
Warning: Illegal string offset "2012-06-11 08:30:49" in /in/9FmBJ on line 31
Warning: Uninitialized string offset 2012 in /in/9FmBJ on line 31
Output for 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 Array
(
[date] => 2012-06-11 08:30:49
[diff] => 1125904
)
Notice: A non well formed numeric value encountered in /in/9FmBJ on line 31
Notice: Uninitialized string offset: 2012 in /in/9FmBJ on line 31
Output for 7.3.32 - 7.3.33 Array
(
[date] => 2012-06-11 08:30:49
[diff] => 1125904
)
preferences:dark mode live preview
210.59 ms | 401 KiB | 287 Q