What are some potential pitfalls of using a foreach loop in PHP to display content from an array?

One potential pitfall of using a foreach loop in PHP to display content from an array is that it may throw an error if the array is empty. To avoid this issue, you can check if the array is empty before iterating over it using the foreach loop.

// Check if the array is empty before using a foreach loop
if (!empty($array)) {
    foreach ($array as $item) {
        echo $item;
    }
} else {
    echo "Array is empty.";
}