ID: 27066 Updated by: [EMAIL PROTECTED] Reported By: stitch at tuks dot co dot za -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Windows XP & Linux PHP Version: 4.3.4 New Comment:
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 Use === here (since "test"==0 by design). Previous Comments: ------------------------------------------------------------------------ [2004-01-28 02:49:43] stitch at tuks dot co dot za Description: ------------ When i use foreach to go through an array, and use an if statement to evaluate the $key, it enters into the if statement incorrectly when $key = 0, even though the if statement reads 'if ($key == "test")' It is not supposed to enter when $key = 0, but as the Actual result shows, it does. This does not happen even when $key = 1, tho. I have tested this on both PHP 4.3.4 and PHP 4.0.1 Thank you very much, keep up the good work. Reproduce code: --------------- <? $the_array["aap"] = array("figure"=> "circle", "colour"=>"blue"); $the_array[] = array("figure" => "triangle", "colour"=>"red"); $the_array["test"] = array ("figure" => "sqaure", "colour"=>"neon"); foreach ( $the_array as $key => $value){ if ($key == "test") { echo "\$key = $key\n"; echo "A ". $value["colour"]. " " . $value["figure"]."\n"; } } ?> Expected result: ---------------- The following output in text: $key = test A neon sqaure Actual result: -------------- The following output in text: $key = 0 A red triangle $key = test A neon sqaure ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27066&edit=1