I have a little script that use the function file() for reading the entire file into an array.
$arr = file('file.txt');
The file.txt is structured like this:
john
david
james
So if I debug the array it returns:
array(4) {
[0]=>
string(6) "john
"
[1]=>
string(7) "david
"
[2]=>
string(2) "
"
[3]=>
&string(5) "james"
}
I'm trying to find a way to detect the empty line when I analyze every value of the array in a foreach loop:
foreach ($arr as $value) {
I tried with the empty function but nothing.. I also tried with comparing the value with PHP_EOL
or
, also nothing.
I know that I can avoid empty lines with FILE_IGNORE_NEW_LINES, but I don't need it. I'm just searching for a way to detect this empty lines.