note 123200 added to function.next
| From: | andy at andysdrawings dot co dot uk | Date: | Fri, 05 Oct 2018 13:58:46 +0000 |
| Subject: | note 123200 added to function.next | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209376@lists.php.net to get a copy of this message | ||
brentimus' array_set_pointer function will only work if the array value is unique in the array,
and none of the array values are FALSE. It would be more reliable to use key() instead of current().
For similar reasons it's better to check key() after calling next() to determine whether the
next() element "exists". Simply checking the value returned by next() will produce a false
negative when looking at, for example, the first element of the array: ['one', 0,
'three']
However, it also turns out that the copied array retains the original array's pointer, so
array_set_pointer is not actually required here. The following should work:
<?php
function has_next(array &$array) {
$A_work = $array; // $A_work is a copy of $array including its internal pointer.
next($A_work);
if (key($A_work) === NULL)
return false;
else
return true;
}
?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.205.172.226
----
Manual Page -- http://php.net/manual/en/function.next.php
Edit -- https://master.php.net/note/edit/123200
Del: integrated -- https://master.php.net/note/delete/123200/integrated
Del: useless -- https://master.php.net/note/delete/123200/useless
Del: bad code -- https://master.php.net/note/delete/123200/bad+code
Del: spam -- https://master.php.net/note/delete/123200/spam
Del: non-english -- https://master.php.net/note/delete/123200/non-english
Del: in docs -- https://master.php.net/note/delete/123200/in+docs
Del: other reasons-- https://master.php.net/note/delete/123200
Reject -- https://master.php.net/note/reject/123200
Search -- https://master.php.net/manage/user-notes.php