How can the foreach loop be correctly used to iterate through an array of lines from a text file in PHP?
When iterating through an array of lines from a text file in PHP using a foreach loop, you need to make sure to use the file() function to read the lines into an array first. Then, you can use the foreach loop to iterate through each line in the array.
// Read lines from a text file into an array
$lines = file('file.txt');
// Iterate through each line using a foreach loop
foreach ($lines as $line) {
// Process each line as needed
echo $line;
}