How to Create a PHP Counter Without Taxing the Server
When you process information in PHP through "while" or "for" loops, it's very important to keep track of the loops with a PHP counter. Depending on how you code this counter, it can cause strain on the system and make it operate in a less than optimal manner. The proper way to code such a counter is not complex and will help reduce the overall strain on the server.
Instructions
-
-
1
Open your PHP file that you want to add a counter to.
-
2
Locate the loop where you need to add a counter.
-
-
3
Type (directly above the star of the loop) "$x = 0;" to initialize a localized counter variable outside the loop.
-
4
Go inside the loop and type "$x++;" to make the counter increment by 1 every time the loop executes.
-
1