What is the purpose of the for loop syntax in PHP when writing data to a file?

When writing data to a file in PHP, a for loop can be used to iterate over an array of data and write each element to the file. This allows for efficient and concise writing of multiple data points to a file without having to manually write each one individually.

$data = ["apple", "banana", "orange"];

$file = fopen("fruits.txt", "w");

for ($i = 0; $i < count($data); $i++) {
    fwrite($file, $data[$i] . "\n");
}

fclose($file);