php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28130 array_search doesn't work with file
Submitted: 2004-04-23 20:38 UTC Modified: 2004-04-23 21:48 UTC
From: edschouten at il dot fontys dot nl Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.6 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2004-04-23 20:38 UTC] edschouten at il dot fontys dot nl
Description:
------------
The array_search function works fine when searching through regular arrays, but when you try to search with it from an array made with file(), it doesn't find anything.

Reproduce code:
---------------
example.list:
1
2
3
4
5

bug.php:
<?
        $list = file('example.list');
                                                                                
        print array_search('2', $list);
?>

Expected result:
----------------
1

Actual result:
--------------
<nothing>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-23 21:48 UTC] pollita@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

file() also returns the line endings, try searching for "2\n" or "2\r\n" (depending on your file encoding).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 28 23:00:03 2025 UTC