What is the potential issue with using nested foreach loops in PHP?

Using nested foreach loops in PHP can lead to performance issues, especially with large datasets, as each iteration of the inner loop will be executed for every iteration of the outer loop. To solve this problem, you can consider restructuring your code to avoid nested loops whenever possible. One way to do this is by using array functions like array_map or array_reduce to perform operations on arrays without the need for nested loops.

// Example of restructuring code to avoid nested loops using array_map
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];

$result = array_map(function($item1, $item2) {
    return $item1 * $item2;
}, $array1, $array2);

print_r($result);