What is the purpose of using the variable $newline="\n" in PHP?

When working with text files in PHP, it's important to use the correct newline character based on the operating system. Different operating systems (Windows, Unix, macOS) use different characters to represent a newline in text files. Using the variable $newline="\n" allows you to set the newline character to '\n', which is the Unix-style newline character. This ensures that your PHP code will generate text files with the appropriate newline character for Unix-based systems.

$newline = "\n";

// Example usage:
$file = fopen("example.txt", "w");
fwrite($file, "Line 1" . $newline);
fwrite($file, "Line 2" . $newline);
fclose($file);