0
php array-search returns a blank
In the following code: echo $key returns a blank but echo $text[2] returns the word at that index. Can someone explain why is array-search not working here? It does work when I test it with a key => value type array. <?php $myfile = fopen("test.txt", "r") or die("Unable to open file!"); while(!feof($myfile)) { $text[] = fgets($myfile); } fclose($myfile); $word = $_POST['word']; $key = array_search($word, $text); echo $key ?>
2 Antworten
+ 1
where is the form you are using for this?
0
Thanks for your response. The problem was in the array. The entries all included \n from the test.txt file.