Skip to content

RFC: array_change_keys#1925

Closed
colinodell wants to merge 6 commits into
php:masterfrom
colinodell:rfc/array-change-keys
Closed

RFC: array_change_keys#1925
colinodell wants to merge 6 commits into
php:masterfrom
colinodell:rfc/array-change-keys

Conversation

@colinodell

Copy link
Copy Markdown
Contributor

colinodell and others added 6 commits May 27, 2016 23:04
The original methods used could result in arrays containing duplicate keys.
For example, if you ran this code:

    array_combine([1, 2, 3], function(){ return 'foo'; });

You'd have three array elements with the same keys! Didn't even know that was possible.
Comment thread ext/standard/array.c
}

array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
params = (zval *)safe_emalloc(2, sizeof(zval), 0);

@laruence laruence May 29, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the size is fixed, you could use stack allocated zval[2]

@smalyshev smalyshev added the RFC label Jun 14, 2016
@webdevxp

webdevxp commented Jul 19, 2016

Copy link
Copy Markdown

Should this function be named array_map_key() or array_map_keys() for consistency with other array key related functions?
And because I think it's actually a variant of array_map() that operates on keys instead of values.
But to do so, argument list should match array_map() too.

array_map_key( callable $callback , array $array1 [, array $... ] )

This also make it appear next to array_map() in PHP manual.

@cmb69

cmb69 commented Nov 27, 2018

Copy link
Copy Markdown
Member

What's the status here? The RFC is still listed as being under discussion – are there unresolved issues?

@colinodell

Copy link
Copy Markdown
Contributor Author

Sorry, I've been meaning to withdraw this RFC and replace it with a different implementation, but never got around to fleshing that alternative out. I'll close it for now and post to the mailing list. Thanks for the ping!

@colinodell colinodell closed this Nov 27, 2018
@andrii-pukhalevych

Copy link
Copy Markdown

Can this be reopened if its not hard to implement?
This feature is really neeed.
Chaning keys or changing single key with another preserving position now requires lot of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants