Advent of code 2021/11
Ajax Direct

Answer 195ms

Part 1 : 1723 Part 2 : 505
$grid = grid($input);
$total_flashes = 0;

for ($i = 1; $i < INF; $i++) {
    // Increase all by 1
    $grid = $grid->map(fn ($c) => int($c) + 1);

    // Apply flashing
    $flashes = 0;
    while (true) {
        $flashed = false;
        foreach ($grid->rows() as $y=>$row) foreach ($row as $x=>$cell) {
            if ($cell <= 9) continue;

            $flashed = true;
            $flashes++;
            $grid->set([$x, $y], -INF);

            foreach (neighbors([$x, $y], true) as $ne) {
                if ($grid->get($ne) != null) {
                    $grid->set($ne, $grid->get($ne) + 1);
                }
            }
        }

        if (!$flashed) break;
        if ($flashes == 100) break 2;
    }

    if ($i < 100) {
        $total_flashes += $flashes;
    }

    // Reset all that flashed
    $grid = $grid->map(fn ($c) => $c < 0 ? 0 : $c);
}

$solution_1 = $total_flashes;
$solution_2 = $i;