|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-02-13 18:08 UTC] rtheunissen@php.net
[2019-02-13 18:14 UTC] shorvat at gmail dot com
[2019-02-13 19:28 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2019-02-13 19:28 UTC] requinix@php.net
[2019-02-13 20:55 UTC] spam2 at rhsoft dot net
[2019-02-14 04:45 UTC] shorvat at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
Description: ------------ PHP 7.0.10 & 5.6.25 Key comparation in foreach loop not working as expected when keys are of mixed types (strings and ints) If I use triple-equals operator (===) it works just fine, but it seems it should work with double-equals operator (==) as well. Test script: --------------- $array = array(); $array['word'] = "test 1"; $array['0'] = "test 2"; $array['1'] = "test 3"; foreach($array as $k=>$v) { var_dump($k); if($k == "word") { continue; } print_r($v); } Expected result: ---------------- C:\wamp64\www\tst\array_bug.php:10:string 'word' (length=4) C:\wamp64\www\tst\array_bug.php:10:int 0 test 2 C:\wamp64\www\tst\array_bug.php:10:int 1 test 3 Actual result: -------------- C:\wamp64\www\tst\array_bug.php:10:string 'word' (length=4) C:\wamp64\www\tst\array_bug.php:10:int 0 C:\wamp64\www\tst\array_bug.php:10:int 1 test 3