[英]if (in_array) doesn't seem to be seeing what's in the array, what have I got wrong?
I have a bit of PHP code for searching the first 'column' of a CSV file for a filename, and if it's found it 'removes' it into a 'removed' folder.我有一些 PHP 代码,用于在 CSV 文件的第一个“列”中搜索文件名,如果找到,则将其“删除”到“已删除”文件夹中。
There must be something wrong with my code because if (in_array
is not seeing a name in the array which is identical to $fileNoExtension
. I added the line at the bottom to check, and I get echo'd back to me " [ImportantFile] apparantly is not the same as [ImportantFile]???
"我的代码一定有问题,因为
if (in_array
没有在数组中看到与$fileNoExtension
相同的$fileNoExtension
。我在底部添加了一行进行检查,然后我得到了回声“ [ImportantFile] apparantly is not the same as [ImportantFile]???
”
I've taken the code out which gets fileNoExtension
from $thisFileWithExtension
just so it's not in the way.我已经删除了从
$thisFileWithExtension
获取fileNoExtension
的代码,这样fileNoExtension
$thisFileWithExtension
了。
foreach ($fileArray as $FileWithExtension) {
if (file_exists('PHP/ManualRemove.csv')) {
$csvManualDemos = fopen("PHP/ManualRemove.csv", "r");
while ($csvRows = fgetcsv($csvManualRemove)) {
if (in_array($fileNoExtension, $csvRows)) {
echo "Found on manual remove list. Removed.";
rename("$fileWithExtension", "Removed/$fileWithExtension");
continue;
} else
echo "\n [$fileNoExtension] apparantly is not the same as [$csvRows[0]]???\n";
}
}
}
I'm sure i've got some code wrong somewhere but I can't work it out!我确定我在某处有一些代码错误,但我无法解决! Many thanks :D
非常感谢:D
Apologies for the typo's in my code, guys - they were from editing the code to post here rather than errors in my actual code.为我的代码中的错字道歉,伙计们 - 他们是从编辑代码到这里发布的,而不是我实际代码中的错误。
I found the answer to my problem.我找到了我的问题的答案。 For some reason
in_array
was missing the first row of my CSV.由于某种原因
in_array
缺少我的 CSV 的第一行。 I had saved my CSV as " CSV UTF-8 " instead of just " CSV " which was causing this problem.我已将我的 CSV 保存为“ CSV UTF-8 ”,而不仅仅是导致此问题的“ CSV ”。
You have a case sensitivity issue in your code.您的代码中存在区分大小写的问题。 You have mixed up $FileWithExtension and $fileWithExtension.
你混淆了 $FileWithExtension 和 $fileWithExtension。 They are not the same.
她们不一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.