How can the file_put_contents function be used to append data to a text file in PHP?

To append data to a text file using the file_put_contents function in PHP, you can pass the FILE_APPEND flag as the third parameter. This flag tells the function to append the data to the end of the file instead of overwriting it.

$data = "New data to append to the file.";
file_put_contents('file.txt', $data, FILE_APPEND);