vendredi 19 août 2016

PHP returns true for all files that are run thru if statement

I'm totally stumped. I have a array holding all the files in a directory on my website. I use an if statement within a foreach loop to filter the results. If the file name begins with a certain combination of three letters ("wwa" or "wea" or "swa" or "hta" or "cta" or "twa" or "fra") then that file name is assigned to $alert_string.

For some reason, all of the files return true inside the if statement, so the variable is simply overwritten each time, and the last file scanned is assigned the variable.

Code:

   $alert_files = scandir("/home/prww/public_html/blog/");

   foreach ($alert_files as $values) {
        if ((substr($values, 0, 3)) == ("wwa" or "wea" or "swa" or "hta" or "cta" or "twa" or "fra")) {
            $alert_string = $values;
        }
    }

Files in the directory:

Files in the directory

Clearly, only the file beginning with "hta" should return true in the if statement. So why does every file return true and how can I fix this?

Aucun commentaire:

Enregistrer un commentaire