[英]if (in_array) doesn't seem to be seeing what's in the array, what have I got wrong?
我有一些 PHP 代碼,用於在 CSV 文件的第一個“列”中搜索文件名,如果找到,則將其“刪除”到“已刪除”文件夾中。
我的代碼一定有問題,因為if (in_array
沒有在數組中看到與$fileNoExtension
相同的$fileNoExtension
。我在底部添加了一行進行檢查,然后我得到了回聲“ [ImportantFile] apparantly is not the same as [ImportantFile]???
”
我已經刪除了從$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";
}
}
}
我確定我在某處有一些代碼錯誤,但我無法解決! 非常感謝:D
為我的代碼中的錯字道歉,伙計們 - 他們是從編輯代碼到這里發布的,而不是我實際代碼中的錯誤。
我找到了我的問題的答案。 由於某種原因in_array
缺少我的 CSV 的第一行。 我已將我的 CSV 保存為“ CSV UTF-8 ”,而不僅僅是導致此問題的“ CSV ”。
您的代碼中存在區分大小寫的問題。 你混淆了 $FileWithExtension 和 $fileWithExtension。 她們不一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.