What is the significance of using rtrim when working with file() in PHP and how does it impact the functionality of the code?

When working with the file() function in PHP to read lines from a file, each line includes a newline character at the end (\n or \r\n). This can cause issues when processing the lines, as the newline characters may interfere with comparisons or string operations. Using rtrim() to remove trailing whitespace, including newline characters, ensures that each line is clean and can be processed effectively.

$lines = file('example.txt');
foreach ($lines as $line) {
    $clean_line = rtrim($line);
    // Process the clean line here
}