What is the purpose of using the $i variable in the second line of the code snippet provided?

The purpose of using the $i variable in the second line of the code snippet is to iterate through the elements of the $array variable using a for loop. This allows us to access each element of the array sequentially and perform operations on them.

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

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