What is the best practice for adding a line to a file in PHP?

When adding a line to a file in PHP, it is best practice to open the file in append mode to avoid overwriting existing content. You can achieve this by using the `fopen()` function with the 'a' mode parameter. After opening the file, you can use `fwrite()` to add the new line to the file and then close the file handle using `fclose()`.

$file = fopen('example.txt', 'a');
fwrite($file, "This is a new line to add to the file\n");
fclose($file);