|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36329 0 as second key in array causes false equality in foreach
Submitted: 2006-02-08 05:53 UTC Modified: 2006-02-08 09:03 UTC
From: tbielawa at definitivellc dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: * OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tbielawa at definitivellc dot com
New email:
PHP Version: OS:


 [2006-02-08 05:53 UTC] tbielawa at definitivellc dot com
combination of array with zero as the second key and foreach loop is causing false equality.  See simple example below...

./configure --with-apxs=/work/st/daemons/apache/bin/apxs --disable-libxml --prefix=/work/st/daemons/php --with-zlib --disable-dom --disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter --without-pear

Reproduce code:
<?php /*>*/;
$value = 'T';
$options = array('T' => 'TBD', '0' => 'Level 0', 
		 '1' => 'Level 1', '2' => 'Level 2'

echo '<br>';
foreach($options as $val => $txt) {

  if($value == $val) {  
    echo "$value == $val<br>" ;


Expected result:
I expect to ONLY see T == T.

Actual result:
result is:

T == T
T == 0


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-08 09:03 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 03:05:52 2022 UTC