简体   繁体   English

使用in_array或strstr,但是if语句似乎无法正常工作

[英]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. 如测试时,if语句似乎无法正常工作:上面的目录中有一个文件,其中包含分析编号,if语句应检查该文件并完成输出。 ( 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). (我要做的就是检查指定目录中是否存在文件名中包含分析号的文件,如果文件夹中不存在分析号,则输出“ completed”,然后输出排队)。

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); $files1 = scandir($folder);之后打印$files1 array $files1 = scandir($folder); and see what the array contains 看看数组包含什么

after that print the $analysisno value and check if the value actually in the array. 之后,打印$analysisno值,并检查该值是否实际在数组中。

your code seems good 您的代码似乎不错

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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