What potential issue could arise from using multiple fwrite statements in PHP?
Using multiple fwrite statements in PHP can lead to performance issues as each fwrite call will result in a separate I/O operation, which can be inefficient when writing to a file multiple times. To solve this issue, you can buffer the data in memory and then write it to the file in a single fwrite call.
// Open the file in write mode
$file = fopen("data.txt", "w");
// Buffer the data in memory
$data = "First line\n";
$data .= "Second line\n";
$data .= "Third line\n";
// Write the buffered data to the file in a single fwrite call
fwrite($file, $data);
// Close the file
fclose($file);