3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{ "title":"event 1", "timeFrom":"2019-11-16 19:00:00", "timeTo":"2019-11-18 22:00:00", "listText":"text of the event", "url":"https://url", "imageUrl":"https://image.jpg", "locations":{ "title":"Location name", "url":"https://location" } }, { "title":"event 2", "timeFrom":"2019-11-20 19:00:00", "timeTo":"2019-11-20 22:00:00", "listText":"text of the event", "url":"https://url", "imageUrl":"https://image.jpg", "locations":{ "title":"Location name", "url":"https://location" } }, { "title":"event 3", "timeFrom":"2019-11-17 19:00:00", "timeTo":"2019-11-17 22:00:00", "listText":"text of the event", "url":"https://url", "imageUrl":"https://image.jpg", "locations":{ "title":"Location name", "url":"https://location" }}]'; function find_events($events, $date) { $date = new DateTime($date); foreach ($events as $event) { $from = (new DateTime($event['timeFrom']))->setTime(0,0,0); $to = (new DateTime($event['timeTo']))->setTime(0,0,0); if ($date >= $from && $date <= $to) { echo "{$event['title']} ({$event['listText']}) from {$event['timeFrom']} to {$event['timeTo']}\n"; } } } $events = json_decode($json, true); find_events($events, '2019-11-17');
Output for 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.29, 7.4.0 - 7.4.21, 8.0.0 - 8.0.8
event 1 (text of the event) from 2019-11-16 19:00:00 to 2019-11-18 22:00:00 event 3 (text of the event) from 2019-11-17 19:00:00 to 2019-11-17 22:00:00
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/qEh2r on line 42
Process exited with code 255.
Output for 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_OBJECT_OPERATOR in /in/qEh2r on line 42
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qEh2r on line 42
Process exited with code 255.

preferences:
488.74 ms | 534 KiB | 15 Q