Bug #63226 [Opn->Nab]: Mixed array index iteration has broken key=>value pair
| From: | nikic@php.net | Date: | Fri, 05 Oct 2012 17:13:18 +0000 |
| Subject: | Bug #63226 [Opn->Nab]: Mixed array index iteration has broken key=>value pair | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173913@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63226&edit=1
ID: 63226
Updated by: nikic@php.net
Reported by: nicholas dot puleo at gmail dot com
Summary: Mixed array index iteration has broken key=>value
pair
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Ubuntu 12.0.4.1 LTS
PHP Version: 5.4.7
Block user comment: N
Private report: N
New Comment:
0 == "text", that's why you see it twice. If you want a strict string check use $k
=== "text".
Previous Comments:
------------------------------------------------------------------------
[2012-10-05 16:47:57] nicholas dot puleo at gmail dot com
Description:
------------
If getting an array with mixed index types (in this case it was served from LDAP)
- iterating over using a foreach loop yielded incorrect key values on the first
changed index from associative to numerical.
Test script:
---------------
<?php
$d = array();
$d['text'] = 1;
$d[0] = 1;
$d[1] = 2;
foreach ($d as $k=>$v) {
if ($k == "text") {
echo 'Should Only See Once';
} else {
echo $v;
}
}
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63226&edit=1