3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates[] = array("date" => "2016-02-18 02:00:00", "duration" => "600"); // 10 mins $dates[] = array("date" => "2016-02-18 02:05:00", "duration" => "300"); // 5 mins $dates[] = array("date" => "2016-02-18 02:10:00", "duration" => "600"); $dates[] = array("date" => "2016-02-18 02:25:00", "duration" => "300"); $dates[] = array("date" => "2016-02-18 02:30:00", "duration" => "600"); $children = array("callum" => "1028", "daniel" => "1029"); $closeDate[] = array("date" => "2016-02-18 02:00:00", "duration" => "600"); // 10 mins function returnClosestDate($child){ global $initialLoop; global $closeDate; global $dates; foreach ($dates as $key => $date) { $dateToCompare = strtotime($date); $diff = $firstTime - $dateToCompare; if ($diff < 0) $diff *= -1; if (count($closeDate) == 0) { $closeDate[][$child] = array("date" => $date, "diff" => $diff); continue; } for ($x = 0; $x <= count($closeDate); $x++) { if(isset($closeDate[$x])){ if ($diff < $closeDate[$x][$child]["diff"]) { $closeDate[$x][$child] = array("date" => $date, "diff" => $diff); } } } //if(!alreadyExistInArray($closeDate, $date, $child)){ //if ($diff < $closeDate[$key-1]["diff"]) { //$closeDate[$key] = array("child" => $child, "date" => $date, "diff" => $diff); // } //} } echo "<pre>"; print_r($closeDate); echo "</pre>"; exit; } function alreadyExistInArray($closeDate, $date, $child){ foreach($closeDate as $key => $close){ if($close["child"] === $child) return true; } } foreach($children as $key => $child){ returnClosestDate($child); }
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
Fatal error: Uncaught TypeError: strtotime(): Argument #1 ($datetime) must be of type string, array given in /in/mjvJs:20 Stack trace: #0 /in/mjvJs(20): strtotime(Array) #1 /in/mjvJs(55): returnClosestDate('1028') #2 {main} thrown in /in/mjvJs on line 20
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Notice: Trying to access array offset on value of type null in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Notice: Trying to access array offset on value of type null in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Notice: Trying to access array offset on value of type null in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Notice: Trying to access array offset on value of type null in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Notice: Trying to access array offset on value of type null in /in/mjvJs on line 31 <pre>Array ( [0] => Array ( [date] => 2016-02-18 02:00:00 [duration] => 600 ) ) </pre>
Output for 7.3.32 - 7.3.33
Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 <pre>Array ( [0] => Array ( [date] => 2016-02-18 02:00:00 [duration] => 600 ) ) </pre>
Output for 5.6.0 - 5.6.27, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 Warning: strtotime() expects parameter 1 to be string, array given in /in/mjvJs on line 20 Notice: Undefined variable: firstTime in /in/mjvJs on line 21 Notice: Undefined offset: 1028 in /in/mjvJs on line 31 <pre>Array ( [0] => Array ( [date] => 2016-02-18 02:00:00 [duration] => 600 ) ) </pre>

preferences:
203.37 ms | 404 KiB | 228 Q