What are the best practices for structuring loops in PHP to ensure optimal functionality and prevent endless iterations?

When structuring loops in PHP, it's important to ensure that the loop termination conditions are correctly set to prevent endless iterations. One common practice is to use a counter variable that increments with each iteration and compare it against a predefined limit. Another approach is to use conditional statements within the loop to check for specific conditions that would warrant exiting the loop. By following these best practices, you can ensure optimal functionality and prevent infinite loops.

// Example of using a counter variable to limit loop iterations
$limit = 10;
$counter = 0;

while ($counter < $limit) {
    // Loop logic here
    $counter++;
}