|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27066 Variable with value 0 is not evaluated correctly within if statement
Submitted: 2004-01-28 02:49 UTC Modified: 2004-01-28 05:40 UTC
From: stitch at tuks dot co dot za Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.4 OS: Windows XP & Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: stitch at tuks dot co dot za
New email:
PHP Version: OS:


 [2004-01-28 02:49 UTC] stitch at tuks dot co dot za
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-28 05:40 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Use === here (since "test"==0 by design).

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 20:01:29 2024 UTC