jeudi 26 juillet 2018

How would I modify this fgetcsv to check multiple columns (not just one!)

I have a working script below which checks a column (1) for something and if found, looks at the adjacent column (0) and does some stuff. (i've excluded stuff above the important code but it loops round every file in a directory as $thisGame or thisGameNoExtension which is the same just with no file extension!

$csvFile = fopen("ManualRegionDupes.csv", "r");
while ($csvRows = fgetcsv($csvFile))
{
    if ($csvRows[1] == $thisGameNoExtension)
    {
        $primaryGame = $csvRows[0];

        $fileExtension = pathinfo($thisGame, PATHINFO_EXTENSION);
        $fileCheck = trim(shell_exec("ls -1 " . escapeshellarg($primaryGame) . "." . escapeshellarg($fileExtension) . " 2>/dev/null"));
        if ($fileCheck)
        {
            echo "\033[00;33m is on the Manual Region Dupes list and primary version detected. Moved to Removed folder\n";
            shell_exec("mv " . escapeshellarg($thisGame) . " Removed/");
            continue 2;
        }
        else
        {
            echo "\033[00;33m is on the Manual Region Dupes list but primary version is missing. Kept.\n";
            continue 2;
        }
    }
}
fclose($csvFile);

I need to create a way of looking at 3 columns (1,2 & 3) not just one. If any of these columns contain what i'm looking for then I want to continue the script. I'm not sure how to acheive this. I've tried:

if ($csvRows[1,2,3] == $thisGameNoExtension)

and also

`if ($csvRows[1] == $thisGameNoExtension) || if ($csvRows[2] == $thisGameNoExtension) || if ($csvRows[3] == $thisGameNoExtension)

But both are incorrect syntax - hopefully they show what i'm trying to acheive though! I'm sure there is a fairly simple solution, apologies for being a dimwit and thankyou in advance for any help you can give me!

Many thanks.

Aucun commentaire:

Enregistrer un commentaire