3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getItem($date, $startDate, $skipped_days){ $item = array('a','b','c','b','c'); $diff = date_create($startDate)->diff(date_create($date)); if($diff->invert) return false; //error $date < $startDate return $item[($diff->days - $skipped_days) % 5]; } //example for use $startDate = '2019-10-01'; $skipday = '2019-10-07'; $skipped_days = 0; $selected_start_date = '2019-10-01'; $selected_end_date = '2019-10-10'; $dates_array = array(); $current_date = strtotime($selected_start_date); $last_date = strtotime($selected_end_date); while( $current_date <= $last_date ) { $dates_array[] = date('Y-m-d', $current_date); $current_date = strtotime('+1 day', $current_date); } for($i=0; $i<count($dates_array); $i++) { $today = $dates_array[$i]; $code = getItem($today, $startDate, $skipped_days); if($dates_array[$i] == $skipday) { $code = "SKIP"; $skipped_days++; } echo $today." ".$code."</br>\n"; }
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.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
2019-10-01 a</br> 2019-10-02 b</br> 2019-10-03 c</br> 2019-10-04 b</br> 2019-10-05 c</br> 2019-10-06 a</br> 2019-10-07 SKIP</br> 2019-10-08 b</br> 2019-10-09 c</br> 2019-10-10 b</br>
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::diff() in /in/CK3f3 on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Call to undefined function date_create() in /in/CK3f3 on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/CK3f3 on line 5
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
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/CK3f3 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/CK3f3 on line 5
Process exited with code 255.

preferences:
167.14 ms | 412 KiB | 5 Q