How can PHP developers prevent overwriting existing data when using fopen() in PHP?

When using fopen() in PHP to write to a file, developers can prevent overwriting existing data by using the 'a' flag instead of the 'w' flag. The 'a' flag will append data to the end of the file without overwriting existing content.

$file = fopen('example.txt', 'a');
fwrite($file, 'New data to append to the file');
fclose($file);