3v4l.org

run code in 300+ PHP versions simultaneously
<?php # The events array. $events = [ [ "title" => "Title 1", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2017-05-25" ], [ "title" => "Title 2", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2018-05-25" ], [ "title" => "Title 3", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2018-05-27" ], [ "title" => "Title 3", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2018-07-15" ], [ "title" => "Title 4", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2019-01-02" ] ]; # Create an array to store the data. $grouped = []; # Iterate over every event. foreach ($events as $event) { # Format and save the date as 'Month Year'. $monthYear = date("F Y", strtotime($event["start_date"])); # Define the key of the object as as an array, if not already defined. $grouped[$monthYear] = $grouped[$monthYear] ?? []; # Insert the title to the array corresponding to the formatted date. $grouped[$monthYear][] = $event["title"]; } # Iterate over every key - value. foreach ($grouped as $key => $value) { # Print the 'Month Year' key. echo $key . "\n"; # Iterate over every title and print it. foreach ($value as $title) echo "- $title\n"; # Separate each group with an empty line. echo "\n"; }
Output for 7.1.0 - 7.1.25, 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
May 2017 - Title 1 May 2018 - Title 2 - Title 3 July 2018 - Title 3 January 2019 - Title 4
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
216.77 ms | 407 KiB | 5 Q