<?php declare(strict_types=1); \$input = <<<\'PHP\' MMMSXXMASM MSAMXMSMSA AMXSXMAAMM MSAMASMSMX XMASAMXAMM XXAMMXXAMA SMSMSASXSS SAXAMASAAA MAMMMXMMMM MXMXAXMASX PHP; \$grid = array_map( static fn (string \$row): array => mb_str_split(\$row), explode(\"\\n\", \$input), ); \$found = 0; foreach (\$grid as \$y => \$row) \{ foreach (\$row as \$x => \$character) \{ if (\$character === \'A\') \{ if (\$grid[\$y - 1][\$x - 1] === \'M\' && \$grid[\$y + 1][\$x + 1] === \'S\' && \$grid[\$y - 1][\$x + 1] === \'S\' && \$grid[\$y + 1][\$x - 1] === \'M\') \{ \$found++; \} if (\$grid[\$y - 1][\$x - 1] === \'S\' && \$grid[\$y + 1][\$x + 1] === \'M\' && \$grid[\$y - 1][\$x + 1] === \'M\' && \$grid[\$y + 1][\$x - 1] === \'S\') \{ \$found++; \} if (\$grid[\$y - 1][\$x - 1] === \'S\' && \$grid[\$y + 1][\$x + 1] === \'M\' && \$grid[\$y - 1][\$x + 1] === \'S\' && \$grid[\$y + 1][\$x - 1] === \'M\') \{ \$found++; \} if (\$grid[\$y - 1][\$x - 1] === \'M\' && \$grid[\$y + 1][\$x + 1] === \'S\' && \$grid[\$y - 1][\$x + 1] === \'M\' && \$grid[\$y + 1][\$x - 1] === \'S\') \{ \$found++; \} \} \} \} return \$found;