note 109771 added to control-structures.foreach
| From: | RauliK. | Date: | Sat, 18 Aug 2012 11:52:16 +0000 |
| Subject: | note 109771 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190130@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 114.73.112.42
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/109771
Del: integrated -- https://master.php.net/note/delete/109771/integrated
Del: useless -- https://master.php.net/note/delete/109771/useless
Del: bad code -- https://master.php.net/note/delete/109771/bad+code
Del: spam -- https://master.php.net/note/delete/109771/spam
Del: non-english -- https://master.php.net/note/delete/109771/non-english
Del: in docs -- https://master.php.net/note/delete/109771/in+docs
Del: other reasons-- https://master.php.net/note/delete/109771
Reject -- https://master.php.net/note/reject/109771
Search -- https://master.php.net/manage/user-notes.php