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 = []; foreach ($array as $v) { if ($v === 'STOPSALES') { unset($ref); continue; } if (!isset($ref)) { $ref = [$v]; $result[] = &$ref; } else { $ref[] = $v; } } var_export($result);

preferences:
83.89 ms | 1177 KiB | 5 Q