liliget
liliget

Reputation: 381

PHP - csv in_array function check

I am trying to pass if() statement with !in_array() check for the generated csv file.

End result is returning false for some reason, and I can not find what am I doing wrong. I am trying to pass false statement and continue with code execution.

Input:

Upvotes: 0

Views: 97

Answers (1)

Waqas Hafeez
Waqas Hafeez

Reputation: 160

you're searching the strings without reading the file you should first open the file , read it then you should find string in array, I've pasted below code just for your reference which is searching the string in csv file after opening and reading.

$file = fopen("test.csv", "r");
$str = "materials";
while (($data = fgetcsv($file)) !== false)
{
    if(in_array($str, $data))
    {
        foreach ($data as $i)
        {
            echo $i."<br>";
        }   
    }
}
fclose($file);

Upvotes: 1

Related Questions