我通過file()命令將文本文件的內容放入數組中。當我嘗試搜索特定值的數組時,它似乎沒有返回任何值,但是當我查看數組的內容時,我正在搜索的值在那裏。用於將文本轉換成數組php array_search不返回值
代碼:
$usernameFileHandle = fopen("passStuff/usernames.txt", "r+");
$usernameFileContent = file("passStuff/usernames.txt");
fclose($usernameFileHandle);
代碼搜索陣列
$inFileUsernameKey = array_search($username, $usernameFileContent);
Usernames.txt包含
Noah
Bob
Admin
也是如此的$ usernameFileContent陣列。爲什麼array_search不起作用,有沒有更好的方法來做到這一點。請原諒我的PHP noob-ness,謝謝。
謝謝。這工作完美。 –