So I'm brand new to PHP and am trying to accomplish something pretty simple. Import a text file to an array, have a foreach go through that array looking for a value, and printing the value if found.
Here is what I have tried so far:
$testers = file('test.txt');
foreach ($testers as $test) {echo $test . "<br />";}
This works great, each line is printed. Perfect. I then add an IF statement.
$testers = file('test.txt');
foreach ($testers as $test) {if ($test){echo $test . "<br />";}}
Also working fine, seems to be returning data. Now if I try and add an operator, it all falls apart.
$testers = file('test.txt');
foreach ($testers as $test) {if ($test == "One"){echo $test . "<br />";}}
I should say, the text file has in it numbers on each line from "One" to "Six" I also tried:
$testers = file('test.txt');
foreach ($testers as $test) {if ($test === "One"){echo $test . "<br />";}}
This also returned nothing...
Any insight would be awesome! Thanks!
What exactly am I missing here? Why is this if statement not returning the value I'm looking for?!
trim($test) == 'One'