What are some common errors or pitfalls to watch out for when coding a counter in PHP?

One common error when coding a counter in PHP is forgetting to initialize the counter variable before trying to increment it. This can lead to unexpected results or errors in the code. To solve this, make sure to initialize the counter variable to 0 before incrementing it.

// Initialize counter variable
$counter = 0;

// Increment the counter
$counter++;