php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64129 bug in in_array
Submitted: 2013-02-01 19:05 UTC Modified: 2013-02-01 19:17 UTC
From: email dot fivemin at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.3 OS: All
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: email dot fivemin at gmail dot com
New email:
PHP Version: OS:

 

 [2013-02-01 19:05 UTC] email dot fivemin at gmail dot com
Description:
------------
this code return 1
i have null member and null isn't zero!
<?
$t="1,2,";
$v=explode(",",$t);
print_r($v);
echo in_array(0,$v);
echo "\n";
?>

Test script:
---------------
<?
$t="1,2,";
$v=explode(",",$t);
print_r($v);
echo in_array(0,$v);
echo "\n";
?>

Expected result:
----------------
in_array function return 0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-01 19:10 UTC] email dot fivemin at gmail dot com
-Operating System: linux +Operating System: All -PHP Version: 5.3Git-2013-02-01 (Git) +PHP Version: 5.3.3
 [2013-02-01 19:10 UTC] email dot fivemin at gmail dot com
edit
 [2013-02-01 19:17 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-02-01 19:17 UTC] rasmus@php.net
You want:
in_array(0,$v,true);
then. The code is behaving correctly because you are doing a non-strict search 
and you have and empty element which will match 0 with a non-strict match.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 16:01:34 2025 UTC