note 73075 deleted from function.next by bjori
| From: | bjori@php.net | Date: | Sun, 17 Jun 2007 19:33:45 +0000 |
| Subject: | note 73075 deleted from function.next by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127502@lists.php.net to get a copy of this message | ||
Note Submitter: deadimp at gmail dot com
----
There ought to be some sort of peek function, like an i/o stream in C/C++...
I've looked through the documentation here, but I haven't found anything.
A simple implementation:
<?php
function peek(&$array) { //Peek to next element on array stack
$ret=next($array);
prev($array);
return $ret;
}
?>
I'm not sure if there should be any more references with $ret (for efficiency).
I'm using this to see if it's the last element on the stack.
<?php
foreach ($array as $a) {
...
if (peek($array)!==false) ...;
}
?>
Useful for extended implode-type functionality.