我在下面有一个工作脚本,它检查列 (1) 中的某些内容,如果找到,则查看相邻的列 (0) 并执行一些操作。(我已经排除了重要代码之上的内容,但它循环了目录中的每个文件,$thisGame
或者thisGameNoExtension
是相同的,只是没有文件扩展名!
$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);
我需要创建一种查看 3 列(1,2 和 3)而不仅仅是一个列的方式。如果这些列中的任何一个包含我正在寻找的内容,那么我想继续编写脚本。我不知道如何实现这一点。我试过了:
if ($csvRows[1,2,3] == $thisGameNoExtension)
并且
`if ($csvRows[1] == $thisGameNoExtension) || if ($csvRows[2] == $thisGameNoExtension) || if ($csvRows[3] == $thisGameNoExtension)
但两者都是不正确的语法 - 希望它们显示出我正在努力实现的目标!我敢肯定有一个相当简单的解决方案,很抱歉我是个笨蛋,并提前感谢您提供的任何帮助!
非常感谢。
这是非常基本的东西,但是:
if ($csvRows[1] == $thisGameNoExtension || $csvRows[2] == $thisGameNoExtension || $csvRows[3] == $thisGameNoExtension) {
您不必if
为每个谓词指定关键字。
编辑:响应评论,将您的if
声明更改为:
if (in_array($thisGameNoExtension, array_slice($csvRows, 0, 3))) {
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句