|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-01-28 05:40 UTC] mgf@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 22:00:01 2025 UTC |
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