$array = file("file.txt");
foreach ($array as $row) {
$line = explode("|",$row);
echo "Name: $line[0], Email: $line[1]<p>";
}
echo count($array) . "<p>";
if (in_array("John Doe", $line)) {
echo "The name John Doe is in this file<p>";
} else {
echo "He ain't here!<p>";
}
The array you actually want is inside of the $line array and not the $array array. Remember, the $array array has the name and pipe and an email address. In your count of the array it says 1. 1 Row, get it? So, even though John Doe is in the array, it isn't parse as a separate component within the array. BUT, in the $line array (where you explode the $row of the FOREACH, the value of John Doe exists in the $line[0] component within the array.
So change your in_array() call to the $line array instead, and it will work. Of course, this won't work if your file has more than one row, unless each row had the name John Doe as the name.
To make it work for multiple rows, you need to move the third part into the FOREACH Loop, and call the compare to a variable containing the name, instead of hard-coding the name into your in_array() function.