-
-
Notifications
You must be signed in to change notification settings - Fork 143
[PHP 8.5] Add array_first
and array_last
#525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Conversation
I'm afraid that the current var_dump(array_slice(['a' => 2, 'b' => 1], -1, 1)[0]); outputs a warning telling |
I guess array_key_last should be used then |
@nicolas-grekas is it OK to bump the minimum PHP version to 7.3? If we have array_key_first/last, it would make this much more cleaner. |
Ah right, then current(array_slice()) should do it |
Adds polyfills for the PHP 8.5's `array_first` and `array_last` functions. The polyfills would have been a bit cleaner if we used the `array_key_first` and `array_key_last` functions, but they were added in PHP 7.3, and are not available on PHP 7.2. This adds the same tests from php-src patch. - [RFC: `array_first()` and `array_last()`](https://wiki.php.net/rfc/array_first_last) - [php-src commit](php/php-src@168343d) - [PHP.Watch polyfill for PHP 8.0+](https://php.watch/versions/8.5/array_first-array_last) Co-authored-by: Nicolas Grekas <[email protected]>
Updated with |
Adds polyfills for the PHP 8.5's
array_first
andarray_last
functions.The polyfills would have been a bit cleaner if we used the
array_key_first
andarray_key_last
functions, but they were added in PHP 7.3, and are not available on PHP 7.2.This adds the same tests from php-src patch.
array_first()
andarray_last()