3v4l.org

run code in 300+ PHP versions simultaneously
<?php $exhibitions = [ [ 'exhibition_title' => 'Picasso', 'venue_name' => 'Gallery 1', 'room_name' => 'Room 4', 'start_date' => '2023-11-15', 'end_date' => '2023-11-17', 'room_id' => 261, 'exhibition_id' => 3540, 'venue_order' => 2, ], [ 'exhibition_title' => 'Monet', 'venue_name' => 'Gallery 4', 'room_name' => 'Room 2', 'start_date' => '2023-10-30', 'end_date' => '2023-11-03', 'room_id' => 274, 'exhibition_id' => 8417, 'venue_order' => 1, ] ]; $result = []; foreach ($exhibitions as $row) { $dateObjects = new DatePeriod( new DateTime($row['start_date']), new DateInterval('P1D'), new DateTime($row['end_date']), DatePeriod::INCLUDE_END_DATE ); foreach ($dateObjects as $d) { $result[] = $row + ['date' => $d->format("Y-m-d")]; } } var_export($result);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array ( 0 => array ( 'exhibition_title' => 'Picasso', 'venue_name' => 'Gallery 1', 'room_name' => 'Room 4', 'start_date' => '2023-11-15', 'end_date' => '2023-11-17', 'room_id' => 261, 'exhibition_id' => 3540, 'venue_order' => 2, 'date' => '2023-11-15', ), 1 => array ( 'exhibition_title' => 'Picasso', 'venue_name' => 'Gallery 1', 'room_name' => 'Room 4', 'start_date' => '2023-11-15', 'end_date' => '2023-11-17', 'room_id' => 261, 'exhibition_id' => 3540, 'venue_order' => 2, 'date' => '2023-11-16', ), 2 => array ( 'exhibition_title' => 'Picasso', 'venue_name' => 'Gallery 1', 'room_name' => 'Room 4', 'start_date' => '2023-11-15', 'end_date' => '2023-11-17', 'room_id' => 261, 'exhibition_id' => 3540, 'venue_order' => 2, 'date' => '2023-11-17', ), 3 => array ( 'exhibition_title' => 'Monet', 'venue_name' => 'Gallery 4', 'room_name' => 'Room 2', 'start_date' => '2023-10-30', 'end_date' => '2023-11-03', 'room_id' => 274, 'exhibition_id' => 8417, 'venue_order' => 1, 'date' => '2023-10-30', ), 4 => array ( 'exhibition_title' => 'Monet', 'venue_name' => 'Gallery 4', 'room_name' => 'Room 2', 'start_date' => '2023-10-30', 'end_date' => '2023-11-03', 'room_id' => 274, 'exhibition_id' => 8417, 'venue_order' => 1, 'date' => '2023-10-31', ), 5 => array ( 'exhibition_title' => 'Monet', 'venue_name' => 'Gallery 4', 'room_name' => 'Room 2', 'start_date' => '2023-10-30', 'end_date' => '2023-11-03', 'room_id' => 274, 'exhibition_id' => 8417, 'venue_order' => 1, 'date' => '2023-11-01', ), 6 => array ( 'exhibition_title' => 'Monet', 'venue_name' => 'Gallery 4', 'room_name' => 'Room 2', 'start_date' => '2023-10-30', 'end_date' => '2023-11-03', 'room_id' => 274, 'exhibition_id' => 8417, 'venue_order' => 1, 'date' => '2023-11-02', ), 7 => array ( 'exhibition_title' => 'Monet', 'venue_name' => 'Gallery 4', 'room_name' => 'Room 2', 'start_date' => '2023-10-30', 'end_date' => '2023-11-03', 'room_id' => 274, 'exhibition_id' => 8417, 'venue_order' => 1, 'date' => '2023-11-03', ), )
Output for 8.1.0 - 8.1.33
Fatal error: Uncaught Error: Undefined constant DatePeriod::INCLUDE_END_DATE in /in/crkGA:32 Stack trace: #0 {main} thrown in /in/crkGA on line 32
Process exited with code 255.

preferences:
75.8 ms | 409 KiB | 5 Q