|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-06-16 21:12 UTC] tony2001@php.net
[2005-06-19 05:58 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
Description: ------------ The string, '0', is not handled correctly in a foreach loop (and possibly elsewhere). The first loop executes correctly. The second and third loops perform incorrect comparisons. In loops two and three, '0' == 'NOLIMIT' evaluates to true when it should be false. Reproduce code: --------------- $arr = array('0' => '$0', '1000' => '$1,000', '2000' => '$2,000', '3000' => '$3,000', 'NOLIMIT' => 'NO LIMIT'); foreach ($arr as $key => $value) { echo "$key : $value $hi\n"; } echo "\n"; foreach ($arr as $key => $value) { if ($key == 'NOLIMIT') { continue; } echo "$key : $value $hi\n"; } echo "\n"; foreach ($arr as $key => $value) { $hi = ($key == 'NOLIMIT' ? 'hi' : ''); echo "$key : $value $hi\n"; } Expected result: ---------------- 0 : $0 1000 : $1,000 2000 : $2,000 3000 : $3,000 NOLIMIT : NO LIMIT 0 : $0 1000 : $1,000 2000 : $2,000 3000 : $3,000 0 : $0 1000 : $1,000 2000 : $2,000 3000 : $3,000 NOLIMIT : NO LIMIT hi Actual result: -------------- 0 : $0 1000 : $1,000 2000 : $2,000 3000 : $3,000 NOLIMIT : NO LIMIT 1000 : $1,000 2000 : $2,000 3000 : $3,000 0 : $0 hi 1000 : $1,000 2000 : $2,000 3000 : $3,000 NOLIMIT : NO LIMIT hi I am using PHP 5.03 and Apache 2.0.53 on Windows XP, service patch 2.