Advent of code 2022/8
Ajax Direct

Answer 1517ms

Part 1 : 1679 Part 2 : 536625
$grid       = grid($input);
$directions = set(["up", "right", "down", "left"]);

// ==================================================
// > PART 1
// ==================================================
$solution_1 = $grid->filter(fn ($tree, $xy) =>
    !$directions->filter(fn ($dir) => $grid->slice($xy, $dir)->max() < $tree)->empty()
)->cells()->count();

// ==================================================
// > PART 2
// ==================================================
$solution_2 = $grid->map(fn ($tree, $xy) =>
    $directions->map(fn ($dir) => (($stopped = $grid->slice($xy, $dir)->searchNumberOver($tree)) === false ? $grid->slice($xy, $dir)->count() : $stopped + 1))->multiply()
)->cells()->max();