簡體   English   中英

php in_array-無法驗證項目的存在

[英]php in_array - can't verify presence of an item

我正在嘗試檢查從文件填充的數組中是否存在一項,該文件由文件名組成,每行一個,如下所示:
GG.jpg
2J.jpg
WWWW.jpg

到目前為止,我有以下內容:

$UsedAvatars = array();

$UsedAvatars = file('UsedAvatars.txt',  FILE_IGNORE_NEW_LINES );

// This next part is to check that the array has been populated, and
// it works.

for($counter=0; $counter<count($UsedAvatars); $counter++)
{
    echo $counter . "\t" . $UsedAvatars[$counter] . "<br>";
}

echo "<br>";

    // This is hardwired in because I know that it is in the text file
    // used to populate the array and so should return TRUE
    $filename="GG.jpg";

if( in_array( $filename, $UsedAvatars ) )
{
  echo "found";
}

但是,該測試不起作用,並且不會輸出“找到”。 我看不出有什么問題,有人可以幫忙嗎?

嘗試更換

if( in_array( $filename, $UsedAvatars ) )
{
  echo "found";
}

$tmp = array_flip ($UsedAvatars);
if ($tmp[$filename] != "")
    echo "found";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM