3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Set demo vars $year = '2012'; $months = array('10','11','12'); $days = array('01','02','03','04','06','07','08','09','11','12','13','14','16','17','18','19','21','22','23','24','26','27','28','30'); $dateWs = array(); foreach($months AS $month) foreach($days AS $day) $datesWS[] = new DateTime($year.'-'.$month.'-'.$day); // Push DateTime object to the WebService array // Shuffle shuffle($datesWS); // Sort dates usort($datesWS, function ($a, $b){ return ($a == $b) ? 0 : (($a > $b) ? 1 : -1); }); $dateIni = count($datesWS)>0 ? reset($datesWS) : 0; // Get first date $dateEnd = count($datesWS)>0 ? end($datesWS) : 0; // Get last date $interval = new DateInterval('P1D'); // Set date interval as 1 day // Generate dates range and Transform iterator to array $datesRange = iterator_to_array(new DatePeriod($dateIni, $interval, $dateEnd->modify( '+1 day' ))); var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesWS))); die(); // This way seems to work foreach($datesRange AS $date) { if(!in_array($date->format('d/m/Y'),array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesWS)))) $excludeDates[] = $date->format('d/m/Y'); } var_dump($excludeDates); /* // This way should be more efficient, but I'm fed up with it! // Get excluded dates $excludeDates = array_udiff($datesRange, $datesWS, function ($a, $b) { return $a == $b ? 0 : 1; }); // Comment/Uncomment this in order to print this method or the other one // Print array(objects) as array(strings) var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesWS))); var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesRange))); var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$excludeDates))); */ ?>
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
array(72) { [0]=> string(10) "01/10/2012" [1]=> string(10) "02/10/2012" [2]=> string(10) "03/10/2012" [3]=> string(10) "04/10/2012" [4]=> string(10) "06/10/2012" [5]=> string(10) "07/10/2012" [6]=> string(10) "08/10/2012" [7]=> string(10) "09/10/2012" [8]=> string(10) "11/10/2012" [9]=> string(10) "12/10/2012" [10]=> string(10) "13/10/2012" [11]=> string(10) "14/10/2012" [12]=> string(10) "16/10/2012" [13]=> string(10) "17/10/2012" [14]=> string(10) "18/10/2012" [15]=> string(10) "19/10/2012" [16]=> string(10) "21/10/2012" [17]=> string(10) "22/10/2012" [18]=> string(10) "23/10/2012" [19]=> string(10) "24/10/2012" [20]=> string(10) "26/10/2012" [21]=> string(10) "27/10/2012" [22]=> string(10) "28/10/2012" [23]=> string(10) "30/10/2012" [24]=> string(10) "01/11/2012" [25]=> string(10) "02/11/2012" [26]=> string(10) "03/11/2012" [27]=> string(10) "04/11/2012" [28]=> string(10) "06/11/2012" [29]=> string(10) "07/11/2012" [30]=> string(10) "08/11/2012" [31]=> string(10) "09/11/2012" [32]=> string(10) "11/11/2012" [33]=> string(10) "12/11/2012" [34]=> string(10) "13/11/2012" [35]=> string(10) "14/11/2012" [36]=> string(10) "16/11/2012" [37]=> string(10) "17/11/2012" [38]=> string(10) "18/11/2012" [39]=> string(10) "19/11/2012" [40]=> string(10) "21/11/2012" [41]=> string(10) "22/11/2012" [42]=> string(10) "23/11/2012" [43]=> string(10) "24/11/2012" [44]=> string(10) "26/11/2012" [45]=> string(10) "27/11/2012" [46]=> string(10) "28/11/2012" [47]=> string(10) "30/11/2012" [48]=> string(10) "01/12/2012" [49]=> string(10) "02/12/2012" [50]=> string(10) "03/12/2012" [51]=> string(10) "04/12/2012" [52]=> string(10) "06/12/2012" [53]=> string(10) "07/12/2012" [54]=> string(10) "08/12/2012" [55]=> string(10) "09/12/2012" [56]=> string(10) "11/12/2012" [57]=> string(10) "12/12/2012" [58]=> string(10) "13/12/2012" [59]=> string(10) "14/12/2012" [60]=> string(10) "16/12/2012" [61]=> string(10) "17/12/2012" [62]=> string(10) "18/12/2012" [63]=> string(10) "19/12/2012" [64]=> string(10) "21/12/2012" [65]=> string(10) "22/12/2012" [66]=> string(10) "23/12/2012" [67]=> string(10) "24/12/2012" [68]=> string(10) "26/12/2012" [69]=> string(10) "27/12/2012" [70]=> string(10) "28/12/2012" [71]=> string(10) "31/12/2012" }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/9cE5U on line 18
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/9cE5U on line 18
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/9cE5U on line 18
Process exited with code 255.

preferences:
173.67 ms | 401 KiB | 232 Q