3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ["01/06/18", "02/06/18", "03/06/18", "11/06/18","12/06/18", "13/06/18", "14/06/18", "15/06/18","16/06/18", "20/06/18"]; $i =-1; $prev =0; $format = "d/m/y"; Foreach($arr as $val){ $dt = date_create_from_format ($format , $val); $unix = date_timestamp_get($dt); If($unix -$prev > 86400){ $i++; } $res[$i][] = $unix; $prev = $unix; } Foreach($res as $period){ If(count($period) >1){ $periods[] = date($format, min($period)) . " - " . date($format, max($period)); }Else{ $periods[] = date($format, min($period)); } } Var_dump($periods);
Output for 7.1.0 - 7.1.33, 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
array(3) { [0]=> string(19) "01/06/18 - 03/06/18" [1]=> string(19) "11/06/18 - 16/06/18" [2]=> string(8) "20/06/18" }
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:
187.9 ms | 407 KiB | 5 Q