3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates = [ '2021-07-05', '2021-07-06', '2021-07-07', '2021-07-08', '2021-07-09', '2021-07-10', '2021-07-11', '2021-07-12', '2021-07-13', '2021-07-14', '2021-07-15', '2021-07-16', '2021-07-17', '2021-07-18', '2021-07-19', '2021-07-20', '2021-07-21', '2021-07-22', ]; $from = $dates[0]; $to = $from; $result = []; foreach($dates as $date) { if (strtotime($from) + 60 * 60 * 24 * 6 < strtotime($date)) { $result[] = ['from' => $from, 'to' => $to]; $from = $to; } $to = $date; } $result[] = ['from' => $from, 'to' => $to]; print_r($result);
Output for 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
Array ( [0] => Array ( [from] => 2021-07-05 [to] => 2021-07-11 ) [1] => Array ( [from] => 2021-07-11 [to] => 2021-07-17 ) [2] => Array ( [from] => 2021-07-17 [to] => 2021-07-22 ) )
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 Array ( [0] => Array ( [from] => 2021-07-05 [to] => 2021-07-11 ) [1] => Array ( [from] => 2021-07-11 [to] => 2021-07-17 ) [2] => Array ( [from] => 2021-07-17 [to] => 2021-07-22 ) )

preferences:
148.74 ms | 402 KiB | 156 Q