What are the potential pitfalls of nesting FOR loops in PHP?

Nesting FOR loops in PHP can lead to decreased readability and potential performance issues, especially if the loops are deeply nested. To solve this issue, consider refactoring the nested loops into separate functions or using alternative looping structures like foreach loops. This can help improve code clarity and maintainability.

// Example of refactoring nested FOR loops into separate functions

function processNestedData($data) {
    foreach($data as $outerItem) {
        processOuterItem($outerItem);
    }
}

function processOuterItem($outerItem) {
    foreach($outerItem['innerData'] as $innerItem) {
        // Process inner data here
    }
}

$data = [
    ['innerData' => [1, 2, 3]],
    ['innerData' => [4, 5, 6]],
    ['innerData' => [7, 8, 9]],
];

processNestedData($data);