简体   繁体   中英

using in_array or strstr but the if statement does not seem to work correctly

Below is my code for the question mentioned in the title:

                $folder = '/net/comp/home/data/';
                $files1 = scandir($folder);
                $analysisno=($row['ANALYSIS_NUMBER']); //e.g.11wa666
                //if ($test = strstr($folder,'$analysisno'))
                if (in_array($analysisno,$files1))              
                {       
                //echo " --$test completed, match found";
                echo "  <td BGCOLOR=\"#00ff00\">completed</td>\n";              
                }
                else
                {
                echo "  <td BGCOLOR=\"#00ffff\">pending</td>\n";

The if statement does not seem to work correctly, as when testing: there is a file in the directory above which contains an analysis number which the if statement should check and output completed. ( this is the problem).

( All I would like to do is check if a file with the analysis number in its filename is present in the directory specified then output 'completed' if there is no existance of the analysis number in the folder then output queued).

By default the code always outputs 'pending' and does not output completed when necessary.

Thanks for any help.

print the $files1 array after the $files1 = scandir($folder); and see what the array contains

after that print the $analysisno value and check if the value actually in the array.

your code seems good

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM