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);

preferences:
88.57 ms | 1172 KiB | 5 Q