How can you ensure that PHP writes variables to a text file with line breaks after each variable?

To ensure that PHP writes variables to a text file with line breaks after each variable, you can concatenate the variables with the PHP_EOL constant, which represents the end of a line in the system's default line ending. This will ensure that each variable is written on a new line in the text file.

<?php
// Variables to write to the text file
$var1 = "Hello";
$var2 = "World";

// Open the text file in append mode
$file = fopen("output.txt", "a");

// Write variables to the text file with line breaks
fwrite($file, $var1 . PHP_EOL);
fwrite($file, $var2 . PHP_EOL);

// Close the file
fclose($file);
?>