3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $data_inicio = new DateTime('2014-10-01'); $data_final = new DateTime('2014-10-20'); $diferenca_data = $data_final->diff($data_inicio)->format('%d'); $possui_dias_semana = [ 'monday', 'sunday' ]; $dias_semana = [ 'monday' => 'Mon', 'tuesday' => 'Tue', 'wednesday' => 'Wed', 'thursday' => 'Thu', 'friday' => 'Fri', 'saturday' => 'Sat', 'sunday' => 'Sun' ]; $datas_da_semana = []; for($i = 1; $i <= $diferenca_data; $i++) { $data_modificada = $data_inicio->modify('+1 day'); $data = $data_modificada->format('Y-m-d'); $dia_semana = date('D', strtotime($data)); foreach($possui_dias_semana as $dia) { if( strtolower($dias_semana[$dia]) == strtolower($dia_semana)) { $datas_da_semana[] = [ 'date' => $data, 'day' => $dias_semana[$dia] ]; } } } var_dump($datas_da_semana);
Output for 5.4.0 - 7.1.0
array(6) { [0]=> array(2) { ["date"]=> string(10) "2014-10-05" ["day"]=> string(3) "Sun" } [1]=> array(2) { ["date"]=> string(10) "2014-10-06" ["day"]=> string(3) "Mon" } [2]=> array(2) { ["date"]=> string(10) "2014-10-12" ["day"]=> string(3) "Sun" } [3]=> array(2) { ["date"]=> string(10) "2014-10-13" ["day"]=> string(3) "Mon" } [4]=> array(2) { ["date"]=> string(10) "2014-10-19" ["day"]=> string(3) "Sun" } [5]=> array(2) { ["date"]=> string(10) "2014-10-20" ["day"]=> string(3) "Mon" } }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/L9jNO on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/L9jNO on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/L9jNO on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/L9jNO on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/L9jNO on line 6
Process exited with code 255.