'Only last line of text file is read by foreach loop in PHP
I access a text file, which contains several lines (made like this: id||x||y||z).
Then I want to read each line and if the part y is equal to "something", I want to push it into the array $a.
It works, but only the last line of the text file is read by the foreach loop. What am I doing wrong?
<?php
$lines = file("myfile.txt");
$a = array();
foreach ($lines as $line){
list($id,$x,$y,$z) = explode('||', $line);
if ($y === "something"){
$a[] = $y;
}
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
