(int)$str, array_filter(explode("\n", $input), 'is_numeric')); print 'Part 1 answer: ' . solve_part_one($nums) . "\n"; print 'Part 2 answer: ' . solve_part_two($nums) . "\n"; } } function solve_part_one(array $nums): int { for ($i = 0; $i < count($nums); $i++) { for ($j = 0; $j < count($nums); $j++) { if ($nums[$i] + $nums[$j] == 2020) { return $nums[$i] * $nums[$j]; } } } return 0; } function solve_part_two(array $nums): int { for ($i = 0; $i < count($nums); $i++) { for ($j = 0; $j < count($nums); $j++) { for ($k = 0; $k < count($nums); $k++) { if ($nums[$i] + $nums[$j] + $nums[$k] == 2020) { return $nums[$i] * $nums[$j] * $nums[$k]; } } } } return 0; }