note 109771 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 15:52:02 +0000 |
| Subject: | note 109771 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190344@lists.php.net to get a copy of this message | ||
Note Submitter: Rauli K.
----
I have on occasion found when foreach iterates through an array produced by mysql_fetch_array, the
value of a key would is of integer type would always return 0 regardless of the value. The solution
to this I found is in this comparison. I do not believe the cause is mysql_fetch_array or the array
itself but foreach.
foreach($array as $key => $value) {
//original setup used sometimes returning 0 for $value if of integer type. In one recent project
happened in one object function but not another! Reason never determined.
}
foreach($array as $key => $value {
//instead of using $value use $array[$key] to overcome this issue
}
Maybe this explains why I do not see foreach used in Wordpress, but while loops instead.
Can anyone else confirm this?
Thanks,
Rauli