Advent of code 2022/10
Ajax Direct

Answer

Part 1 :
Part 2 :
$cycle  = 0;
$x      = 1;
$cycles = set();

foreach ($input->lines as $line) {
    $cycle++;
    $cycles[$cycle] = $x;

    if (!preg_match("/addx (\-?[0-9]+)/", $line, $match)) continue;
    $cycle++;
    $cycles[$cycle] = $x;
    $x += (int) $match[1];
}

// ==================================================
// > PART 1
// ==================================================
$solution_1 = set([20, 60, 100, 140, 180, 220])->reduce((fn ($s, $c) => $s += ($c * $cycles[$c])), 0);

// ==================================================
// > PART 2
// ==================================================
$solution_2 = $cycles->keys()
    ->reduce((fn ($s, $c) => $s->append(in_array(($c - 1) % 40, range($cycles[$c] - 1, $cycles[$c] + 1)) ? "#" : ".")), scalar(""))
    ->chunk(40)->join("<br>");