echo ($counter = !$counter) ? '1st>': '2nd>';
Ok, here's how that code works:
the ($counter = !$counter) means, in english:
assign the variable $counter to the opposite of the value of $counter. So, if $counter is set to false, !$counter will equal true. The evaluation of !$counter is done before assigning that value to $counter.
So, with each iteration, $counter is set to the opposite of what it was set to before. That is, if counter was true before this call, it will be false after it.
Here's a messy long way to do the same thing
$counter = !$counter; // flip boolean value for counter
echo ($counter == true) ? '1st': '2nd';
get it?