What are some best practices for structuring PHP code when using loops to improve readability and maintainability?

When using loops in PHP code, it is essential to structure the code in a way that improves readability and maintainability. One best practice is to separate the loop logic from the rest of the code by encapsulating it in a separate function or method. This helps to make the code more modular and easier to understand. Additionally, using meaningful variable names and comments can also enhance the readability of the code.

// Example of structuring PHP code with loops for readability and maintainability

function processItems($items) {
    foreach ($items as $item) {
        // Loop logic goes here
        // Process each item
    }
}

$items = [1, 2, 3, 4, 5];
processItems($items);