How does the choice between "\n" and PHP_EOL impact the readability and portability of PHP code across different operating systems?
Using "\n" directly in your PHP code can impact the readability and portability of the code across different operating systems because it represents a newline character specific to Unix-based systems. On Windows-based systems, the newline character is "\r\n". To ensure cross-platform compatibility, it is recommended to use the predefined constant PHP_EOL, which represents the correct newline character for the operating system the script is running on.
// Using PHP_EOL for cross-platform compatibility
echo "Hello" . PHP_EOL;
echo "World" . PHP_EOL;