Re: array position isfirst / islast / valid ?
| From: | Kalle Sommer Nielsen | Date: | Sat, 02 Jan 2010 20:36:07 +0000 |
| Subject: | Re: array position isfirst / islast / valid ? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46594@lists.php.net to get a copy of this message | ||
Hi Oskar
2010/1/2 Oskar Eisemuth <patchnow@gmail.com>:
> Hello
>
> Would it be possible to add functions to know the relative internal array
> position?
>
> I found "[PHP-DEV] RFC array functions" from 2006, but nothing really
> changed.
>
> The need to use next, prev in combination is ridiculous compared to a clean
> array_hasmore or array_pos_islast, as the internals already know this.
> To get an array_valid_position or array_pos_isvalid wouldn't be bad either.
>
> So would it possible to introduce:
>
How about just array_pos() if any. The remaining functions can easily
be implemented in userland like:
function array_pos_isfirst(Array &$array) {
return array_pos($array) == 0;
}
function array_pos_islast(Array &$array) {
return array_pos($array) == (sizeof($array) - 1);
}
I don't think it should be needed to add array_pos_isvalid(), since it
*shouldn't* be possible to point to an invalid position. Rather
"isset($array['key'])" should be used to check if a position is valid.
--
regrads,
Kalle Sommer Nielsen
kalle@php.net