3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = strtotime("01-jan-2018"); $next = strtotime("next day", $start); $festivi = array( "Capodanno" => getMyDate("01-jan-2018"), "Epifania" => getMyDate("06-jan-2018"), "Pasqua" => getMyDate("01-apr-2018"), "Pasquetta" => getMyDate("02-apr-2018"), "Liberazione" => getMyDate("25-apr-2018"), "Lavoratori" => getMyDate("01-mag-2018"), "Repubblica" => getMyDate("02-jun-2018"), "Patrono" => getMyDate("29-jun-2018"), "Ferragosto" => getMyDate("15-aug-2018"), "TuttiSanti" => getMyDate("01-nov-2018"), "Immacolata" => getMyDate("08-dic-2018"), "Natale" => getMyDate("25-dic-2018"), "SantoStefano" => getMyDate("26-dic-2018") ); while($start != strtotime("01 jan 2019")){ if(isFestivo($festivi, $start)) echo date('d/m/Y', $start)."\t".$festivo[getFestivoIndex($festivi, $start)]["descrizione"]."\n"; else if(date('w',$start)==6) echo date('d/m/Y', $start)."\tS\n"; else if(date('w',$start)==7) echo date('d/m/Y', $start)."\tD\n"; else $start = strtotime("next day", $start); $start = strtotime("next day", $start); } function getMyDate($myDate){ return date('d/m/Y', strtotime($myDate)); } function isFestivo($festivi, $myDate){ foreach($festivi as $tempDescription => $tempDate) if($myDate == $tempDate) return true; return false; } function getFestivoIndex($festivi,$myDate){ $count = 0; foreach($festivi as $tempDescription => $tempDate) if($myDate == $tempDate) return $count; else $count++; return -1; }

preferences:
59.91 ms | 402 KiB | 5 Q