3v4l.org

run code in 300+ PHP versions simultaneously
<?php $post = new \stdClass(); $events = array( (object) array( 'ID' => 8717, 'post_author' => 5, 'post_date' => '2020-01-28 10:00:36', 'post_parent' => 2766, 'post_title' => 'Film 1', ), (object) array( 'ID' => 8716, 'post_author' => 5, 'post_date' => '2020-01-28 14:25:36', 'post_parent' => 2769, 'post_title' => 'Film 2', ), (object) array( 'ID' => 8718, 'post_author' => 5, 'post_date' => '2020-01-28 14:00:39', 'post_parent' => 2766, 'post_title' => 'Film 1', ), (object) array( 'ID' => 8719, 'post_author' => 5, 'post_date' => '2020-01-28 14:25:36', 'post_parent' => null, 'post_title' => 'Film 4', ), (object) array( 'ID' => 8720, 'post_author' => 5, 'post_date' => '2020-01-28 14:00:39', 'post_parent' => null, 'post_title' => 'Film 5', ), ); function tribe_event_featured_image($id, $size) { return 'IMAGE'; } function tribe_get_start_date($event, $condition, $format) { return date_create($event->post_date)->format($format); } global $post; $matchedParents = []; foreach ($events as $event) { if (in_array($event->ID, $matchedParents)) { //post_parent has already been output continue; } echo tribe_event_featured_image($event->ID, 'medium' ) . PHP_EOL; echo '<h4>'. $event->post_title . '</h4>' . PHP_EOL; /* display the times for the post_parent */ $eventTimes = []; if (empty($event->post_parent)) { $eventTimes[] = tribe_get_start_date($event, false, $format= 'H:i'); } else { foreach ($events as $subEvent) { if ($event->post_parent === $subEvent->post_parent) { //store the matched events $matchedParents[] = $subEvent->ID; $eventTimes[] = tribe_get_start_date($subEvent, false, $format= 'H:i'); } } } /* optionally sort the times */ natsort($eventTimes); //output the event times as a CSV echo implode(', ', $eventTimes); echo PHP_EOL , PHP_EOL; }
Output for 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
IMAGE <h4>Film 1</h4> 10:00, 14:00 IMAGE <h4>Film 2</h4> 14:25 IMAGE <h4>Film 4</h4> 14:25 IMAGE <h4>Film 5</h4> 14:00
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 IMAGE <h4>Film 1</h4> 10:00, 14:00 IMAGE <h4>Film 2</h4> 14:25 IMAGE <h4>Film 4</h4> 14:25 IMAGE <h4>Film 5</h4> 14:00

preferences:
183.24 ms | 402 KiB | 180 Q