note 99883 modified in function.current by danbrown
| From: | danbrown@php.net | Date: | Mon, 13 Sep 2010 21:39:02 +0000 |
| Subject: | note 99883 modified in function.current by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172526@lists.php.net to get a copy of this message | ||
It would be great to have a function which is just like current, with the difference that it
advances the array pointer to the next element after reading the current value.
When using current() in a loop, you always have to call next(). Including a function that acts like
current() while automatically advancing the array pointer would be more elegant.
It can be implemented like this:
<?php
function currentPlusOne($array) {
$element = current($array);
next($array);
return $element;
}
?>
A native out-of-the-box solution would be ideal, of course.
--was--
It would be great to have a function which is just like current, with the difference that it
advances the array pointer to the next element after reading the current value.
When using current() in a loop, you always have to call next(). Including a function that acts like
current() while automatically advancing the array pointer would be more elegant.
It can be implemented like this:
function currentPlusOne($array) {
$element = current($array);
next($array);
return $element;
}
A native out-of-the-box solution would be ideal, of course.
http://php.net/manual/en/function.current.php