php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64095 in_array does not work correct
Submitted: 2013-01-29 11:30 UTC Modified: 2013-02-18 00:36 UTC
From: jahangiri dot hamid at gmail dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.3Git-2013-01-29 (Git) OS: win 7
Private report: No CVE-ID: None
 [2013-01-29 11:30 UTC] jahangiri dot hamid at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.in-array#refsect1-function.in-array-
returnvalues
---
in_array doesnot work properly 


Test script:
---------------
my array : array is result of print_r of my real array
$arrayvar = Array ( [0] => 90 [1] => a [2] => [3] => 1 [4] => b [5] => [6] => 2 [7] => c [8] => [9] => 4 [10] => d [11] => [12] => 6 [13] => e [14] => [15] => 7 [16] => f [17] => [18] => 8 [19] => g [20] => [21] => 9 [22] => h [23] => [24] => 10 [25] => i [26] => [27] => 11 [28] => j [29] => [30] => 12 [31] => k [32] => [33] => 14 [34] => l [35] => [36] => 100 [37] => m [38] => )

my needle : $key=90;

my code :
in_array($key,$arrayvar);
it return false

Expected result:
----------------
true

Actual result:
--------------
false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-29 11:37 UTC] cataphract@php.net
in_array() looks for values, not keys; see key_exists()
 [2013-01-29 11:37 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2013-01-29 11:39 UTC] jahangiri dot hamid at gmail dot com
-Status: Not a bug +Status: Open
 [2013-01-29 11:39 UTC] jahangiri dot hamid at gmail dot com
i found that this problem is just for index 0 or better to say for forst cell of 
array  it work nice woth other so i add a null value for first cell og array and i 
solve it
 [2013-01-29 13:53 UTC] cataphract@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2013-01-29 13:53 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2013-02-18 00:36 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Mar 13 21:01:32 2025 UTC