What are the advantages of using foreach loop over for loop when iterating through arrays in PHP?

When iterating through arrays in PHP, using a foreach loop is often preferred over a traditional for loop because it simplifies the syntax and makes the code more readable. The foreach loop automatically iterates over each element in the array without the need for manual index management, resulting in cleaner and more concise code. Additionally, foreach loop handles associative arrays seamlessly, making it a versatile choice for iterating through different types of arrays.

// Using foreach loop to iterate through an array
$fruits = array("apple", "banana", "orange");

foreach($fruits as $fruit) {
    echo $fruit . "<br>";
}