What best practices can be followed to handle line breaks and end conditions when parsing files in PHP arrays?

When parsing files into PHP arrays, it's important to handle line breaks and end conditions properly to ensure accurate data processing. One common approach is to use functions like `fgets()` to read the file line by line and check for end conditions, such as reaching the end of the file. Additionally, trimming each line can help remove any extra whitespace or newline characters.

$file = fopen('data.txt', 'r');
$array = [];

while (!feof($file)) {
    $line = trim(fgets($file));
    
    // Check for end conditions
    if (empty($line)) {
        continue;
    }
    
    // Process the line and add to array
    $array[] = $line;
}

fclose($file);

print_r($array);