What are some potential pitfalls when using multiple if statements in a foreach loop in PHP?

Using multiple if statements within a foreach loop can lead to nested conditional logic that can become difficult to manage and read. To avoid this, consider refactoring the logic into separate functions or using switch statements for better readability and maintainability.

// Example of refactoring multiple if statements in a foreach loop
foreach ($array as $item) {
    processItem($item);
}

function processItem($item) {
    if (condition1) {
        // Process item based on condition 1
    } elseif (condition2) {
        // Process item based on condition 2
    } else {
        // Default processing
    }
}