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');

preferences:
95.84 ms | 402 KiB | 5 Q