php.net |  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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tbielawa at definitivellc dot com
New email:
PHP Version: OS:

 

 [2006-02-08 05:53 UTC] tbielawa at definitivellc dot com
Description:
------------
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'
		 );

var_dump($options);
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



Patches

Pull Requests

History

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

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 04:01:29 2025 UTC