What changes can be made to the for loop to avoid the "undefined index" notice when accessing the array element?

When accessing elements in an array within a for loop, the "undefined index" notice occurs when the loop attempts to access an index that does not exist in the array. To avoid this notice, you can check if the index exists before trying to access it. This can be done using the `isset()` function to verify if the index is set in the array.

$array = [1, 2, 3, 4, 5];

for ($i = 0; $i < count($array); $i++) {
    if (isset($array[$i])) {
        echo $array[$i] . " ";
    }
}