note 46773 deleted from control-structures.foreach by sean
| From: | sean@php.net | Date: | Sat, 23 Oct 2004 03:07:23 +0000 |
| Subject: | note 46773 deleted from control-structures.foreach by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78974@lists.php.net to get a copy of this message | ||
Note Submitter: tenoria
----
Remember that when you are comparing an integer with a string, the string will be casted to integer
as a zero. So if you try to compare 0 == anything, this will be TRUE.
http://es2.php.net/manual/en/language.types.string.php
#language.types.string.conversion
imagine you are using a foreach to iterate an array of mixed index:
<?php
$dummy = array (0=>Blue, 1=>Red, solution=>Yellow);
foreach ($dummy as $key=>$color){
if ($key == 'solution'){
echo "The winner is".$color;
}
?>
this will output "Blue", because 0=='solution' is true.
hope this helped some other newbies like me :-)
----
Reason: useless note