note 92125 added to control-structures.for
| From: | timmie dot loots at gmail dot com | Date: | Fri, 10 Jul 2009 05:14:17 +0000 |
| Subject: | note 92125 added to control-structures.for | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158127@lists.php.net to get a copy of this message | ||
@dkimbel13 at gmail dot com
First of all, I'm assuming the comma's you use in the example are supposed to be
semi-colons.
Secondly, I advise against using the example you posted (the for-loop using count() and next(). This
is due to the fact that there is no guarantee the entire array will be iterated. This is because the
result of current() can be false, even if you are not at the end of the array. This occurs if the
array contains a value that evaluates to false.
For example:
<?php
$array = array("value1", false, "value2", "value3");
for (reset($array); current($array); next($array)) {
echo "Element ".key($array)." contains
".current($array)."<br/>";
}
for ($i = 0, $size = count($array); $i < $size; $i++) {
echo "Element {$i} contains {$array[$i]}<br>";
}
?>
----
Server IP: 83.137.20.135
Probable Submitter: 84.105.141.165
----
Manual Page -- http://www.php.net/manual/en/control-structures.for.php
Edit -- https://master.php.net/note/edit/92125
Del: integrated -- https://master.php.net/note/delete/92125/integrated
Del: useless -- https://master.php.net/note/delete/92125/useless
Del: bad code -- https://master.php.net/note/delete/92125/bad+code
Del: spam -- https://master.php.net/note/delete/92125/spam
Del: non-english -- https://master.php.net/note/delete/92125/non-english
Del: in docs -- https://master.php.net/note/delete/92125/in+docs
Del: other reasons-- https://master.php.net/note/delete/92125
Reject -- https://master.php.net/note/reject/92125
Search -- https://master.php.net/manage/user-notes.php