What are the potential pitfalls of using foreach loop on an empty array in PHP?

When using a foreach loop on an empty array in PHP, it can cause a warning or error because the loop will try to iterate over an array with no elements. To avoid this issue, you can check if the array is empty before using the foreach loop.

$array = []; // empty array

if (!empty($array)) {
    foreach ($array as $element) {
        // loop through the elements
    }
} else {
    // handle case of empty array
}