How can the code provided be improved to display the desired output correctly?

The issue with the provided code is that the variable `$i` is not being incremented inside the `for` loop, causing an infinite loop. To solve this issue, we need to increment the value of `$i` inside the loop to iterate through the array elements correctly.

<?php
$names = array("Alice", "Bob", "Charlie", "David");

for ($i = 0; $i < count($names); $i++) {
    echo $names[$i] . "<br>";
}
?>