note 46773 added to control-structures.foreach
| From: | tenoria at osu1 dot php dot net | Date: | Fri, 22 Oct 2004 18:12:01 +0000 |
| Subject: | note 46773 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78955@lists.php.net to get a copy of this message | ||
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 :-)
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46773
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46773&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46773&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46773&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46773&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46773&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46773&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46773&report=yes
Search -- http://master.php.net/manage/user-notes.php