in reply to Boolean counter?

For starters,
if ($toggle) { $toggle = 0; } else { $toggle = 1; }

can be written as

$toggle = $toggle ? 0 : 1;

And if you wanted a bitwise toggle, you could do

$toggle ^= 1;

But you asked for boolean, so you want the even simpler:

$toggle = !$toggle;