advent.of.code.challenge.four.php
            
foreach($array as $command) {
    if(strstr($command, "forward")) {
        $command = intval(str_replace("forward ", "", $command));
        $forwardTotal = $forwardTotal + $command;
        $depth = $depth + ($aimTotal * $command);
    } 
    elseif (strstr($command, "up")) {
        $command = (intval(str_replace("up ", "", $command)) * -1 );
        $aimTotal = $aimTotal + $command;
    }
    elseif (strstr($command, "down")) {
        $command = intval(str_replace("down ", "", $command));
        $aimTotal = $aimTotal + $command;
    }
}

$depth = $depth + $upTotal + $downTotal;

$depthTimesForward = $forwardTotal * $depth;
            
        

Based on your calculations, the planned course doesn't seem to make any sense. You find the submarine manual and discover that the process is actually slightly more complicated.

In addition to horizontal position and depth, you'll also need to track a third value, aim, which also starts at 0. The commands also mean something entirely different than you first thought:

Again note that since you're on a submarine, down and up do the opposite of what you might expect: "down" means aiming in the positive direction.

Puzzle Data

Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth?