foreach ($alphabet as $i => $letter) {
echo (($i % 2) == 1 ? '!' : '') . $letter;
}
$i
is the position of the letter in the array; since array indexes start from 0, even letters will have odd indexes.
$i % 2
is 0
when $i
is even, 1
when it's odd. This is grade school arithmetic, which should be a prerequisite for a programming career.