note 61359 added to control-structures.foreach
| From: | patrik dot mayer at i12 dot de | Date: | Wed, 01 Feb 2006 15:54:52 +0000 |
| Subject: | note 61359 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102817@lists.php.net to get a copy of this message | ||
While running through a foreach construct the array-count decreases...
<?php
$array = array('hi','hey','howdie');
$array_count = count($array); // this is 3
foreach($array AS $key => $value){
//if reeached the entry before the last one
//doesn't work
if($key == (count($array)-1) ){
echo "reached the second last one";
}
//works
if($key == ($array_count-1) ){
echo "reached the second last one";
}
echo "Current #".count($array)."<br/>";
}
?>
----
Server IP: 217.160.72.57
Probable Submitter: 213.172.101.73
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61359
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61359&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61359&report=yes
Search -- http://master.php.net/manage/user-notes.php