3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ //"STOPSALES", "2023-03-10", "2023-03-11", "2023-03-12", "2023-03-13", "2023-03-14", "2023-03-15", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "STOPSALES", "2023-03-27", "2023-03-28", "2023-03-29", "2023-03-30", "2023-03-31", "2023-04-01", "2023-04-02", "2023-04-03", ]; $result = []; $k = 0; foreach ($array as $i => $v) { if ($v !== 'STOPSALES') { if (($array[$i - 1] ?? null) === 'STOPSALES') { ++$k; } $result[$k][] = $v; } } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
array ( 0 => array ( 0 => '2023-03-10', 1 => '2023-03-11', 2 => '2023-03-12', 3 => '2023-03-13', 4 => '2023-03-14', 5 => '2023-03-15', ), 1 => array ( 0 => '2023-03-27', 1 => '2023-03-28', 2 => '2023-03-29', 3 => '2023-03-30', 4 => '2023-03-31', 5 => '2023-04-01', 6 => '2023-04-02', 7 => '2023-04-03', ), )

preferences:
98.15 ms | 1173 KiB | 4 Q