Advent of code 2015/23
Ajax Direct

Answer

Part 1 :
Part 2 :
function solve($r, $lines, $cmds, $jump) {
    for ($i = 0; $i < $lines->count();) {
        $cmd = explode(" ", $lines[$i]->string);

        if (isset($cmds[$cmd[0]])) {
            $r[$cmd[1]] = $cmds[$cmd[0]]($r[$cmd[1]]);
            $i++;
        }

        if (isset($jump[$cmd[0]])) {
            if ($cmd[0] == "jmp") {
                $i += $jump["jmp"](trim($cmd[1], "+"));
            } else {
                $i += $jump[$cmd[0]]($r[trim($cmd[1], ",")], trim($cmd[2], "+"));
            }
        }
    }

    return $r["b"];
}

$cmds = [
    "hlf" => fn ($n) => $n / 2,
    "tpl" => fn ($n) => $n * 3,
    "inc" => fn ($n) => $n + 1
];

$jump = [
    "jmp" => fn ($o) => $o,
    "jie" => fn ($n, $o) => $n % 2 == 0 ? $o : 1,
    "jio" => fn ($n, $o) => $n == 1 ? $o : 1
];

$solution_1 = solve(["a" => 0, "b" => 0], $input->lines, $cmds, $jump);
$solution_2 = solve(["a" => 1, "b" => 0], $input->lines, $cmds, $jump);