Welcome! Log In Create A New Profile

Advanced

[PHP-DEV] [VOTE] array_key_first(), array_key_last(), array_value_first(), array_value_last()

Posted by Woortmann, Enno 
Not sure what timezone you are in; current votes are:

Add array_key_first() and array_key_last()?
- Yes (19)
- No (13)

Add array_value_first() and array_value_last()?
- Yes (16)
- No (17)

The first vote will pass with 59.375%. The second fails at ~48.48%.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Le vendredi 13 juillet 2018, 16:48:29 CEST Levi Morrison a écrit :
> Below is a proof-of-concept for the `array_offset` function [mentioned
> by Nicolas Grekas][2] (which by the way, neither the RFC author nor
> anyone else responded to this suggestion) that is simply a convenience
> wrapper over `array_slice`:
>
> function array_offset(array $input, int $offset): ?array {
> $slice = array_slice($input, $offset, 1, true);
> return count($slice) ? $slice : null;
> }
>
> $assoc = ['one' => 1, 'two' => 2, 'three' => 3];
> $packd = range(1, 4);
>
> var_dump(array_offset($assoc, -1));
> var_dump(array_offset($packd, -1));
>
> var_dump(array_offset($assoc, 0));
> var_dump(array_offset($packd, 0));
>
> Of course, the `array_slice` function can be used to build all of the
> functions described in the RFC, as well.

How would you do that, since array_slice still gives you an associative array as a result?
array_values(array_slice($array, -1, 1, true))[0] is way less readable than array_last_value($array), and the question «how efficient is that and how many array copies are made?» becomes complicated to answer for non-initiated.
While with a native function you expect it to be as efficient as possible to do what you ask it.
(And as you state in your other mail in the end this array_slice solution is not as efficient as you expected)

I would have been fine with array_key($array, $offset=0) and array_value($array, $offset=0) instead of the 4 functions from the RFC to be able to use any offset.

Côme

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Am 09.07.2018 um 13:16 schrieb Woortmann, Enno:

> Hi,
>
> as the discussion got no new contributions I'd like to start the
> voting for the RFC fo add new functions for the handling of outer
> array elements.
>
> https://wiki.php.net/rfc/array_key_first_last
>
> To have a better separation I split up the vote for the functions. The
> first vote covers the functions to handle keys: array_key_first() and
> array_key_last(). The second vote covers the corresponding functions
> to handle the values: array_value_first() and array_value_last().
>
> As this RFC adds functions but doesn't change the language syntax a
> 50% + 1 majority is required for both votes. The votes are open until
> 2018-07-16.
>
> The discussion for this RFC is located at
>
> https://externals.io/message/102245
>
> Regards,
>
> Enno

Hello together,

The vote for this RFC has been closed. The vote for the initially RFC
containing the functions array_key_first() and array_key_last() was
accepted, the vote for the extended RFC (adding also array_value_first()
and array_value_last()) was declined.

I'll update the pull request located at
https://github.com/php/php-src/pull/3256 tomorrow and remove the
array_value functions as well as adopt the code review remarks of
derickr so the PR can be merged for PHP 7.3.

Thanks for the participation,
Enno



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
On 17.07.2018 at 01:13, Enno Woortmann wrote:

> Am 09.07.2018 um 13:16 schrieb Woortmann, Enno:
>
>> https://wiki.php.net/rfc/array_key_first_last
>
> The vote for this RFC has been closed. The vote for the initially RFC
> containing the functions array_key_first() and array_key_last() was
> accepted, the vote for the extended RFC (adding also array_value_first()
> and array_value_last()) was declined.

When time permits, please update the RFC to state that it has been
implemented for PHP 7.3.0 via commit 50516a6[1], and link to the manual
pages[2] (which should be online tomorrow).

[1] http://git.php.net/?p=php-src.git;a=commit;h=50516a6
[2] http://php.net/manual/en/function.array-key-first.php
http://php.net/manual/en/function.array-key-last.php

--
Christoph M. Becker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login