How can nesting multiple foreach loops impact the outcome of storing loop results in PHP?

Nesting multiple foreach loops can impact the outcome of storing loop results in PHP by potentially causing unintended overwriting of variables or unexpected behavior due to variable scope conflicts. To solve this issue, it is recommended to use different variable names for each nested loop to avoid conflicts and ensure that the loop results are stored correctly.

$outerArray = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];

$allValues = [];

foreach ($outerArray as $innerArray) {
    $innerValues = [];
    
    foreach ($innerArray as $value) {
        $innerValues[] = $value;
    }
    
    $allValues[] = $innerValues;
}

print_r($allValues);