3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates_array = ['20241203', '20240115', '20240116', '20240228', '20240229', '20240301']; foreach ($dates_array as $date) { $datetimes[] = new DateTime($date); } foreach ($datetimes as $key=>$date) { $dateStr = $date->format('j'); //check if there's another entry after this one if (isset($datetimes[$key+1])) { //check the if following entry is in the same month and year as this one if ($datetimes[$key+1]->format("ym") == $date->format("ym")) { $dateStr .= ","; } else { $dateStr .= " ".$date->format("F")." & "; } } else { $dateStr .= " ".$date->format("F"); } $date_array[]= $dateStr; } $date_string = join( ' ', $date_array ) ; echo $date_string;
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.14, 8.4.16 - 8.4.17, 8.5.0 - 8.5.2
3 December & 15, 16 January & 28, 29 February & 1 March
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:
112.32 ms | 407 KiB | 5 Q