Req #48543 [Opn->Fbk]: Introduction of a substitute for array_change_key_case which takes a callback.
| From: | levim@php.net | Date: | Wed, 16 Apr 2014 21:57:39 +0000 |
| Subject: | Req #48543 [Opn->Fbk]: Introduction of a substitute for array_change_key_case which takes a callback. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185306@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48543&edit=1
ID: 48543
Updated by: levim@php.net
Reported by: simon at stienen dot name
Summary: Introduction of a substitute for
array_change_key_case which takes a callback.
-Status: Open
+Status: Feedback
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: Arrays related
PHP Version: 5.3.0RC3
Block user comment: N
Private report: N
New Comment:
Is this something you are still interested in?
Previous Comments:
------------------------------------------------------------------------
[2009-06-13 11:21:40] simon at stienen dot name
Description:
------------
While array_change_key_case allows for changing array keys in regards to capitalization, it is very
limited in its function.
Therefore I request the introduction of a new function (for the sake of the discussion, I'll
call it "array_change_keys") that takes an array and a callback and then calls the
callback for each key, passing the key as a parameter (possibly also passing the value as another
parameter) and replaces the old key with the return value of the function call - under the same
constraints as mentioned in http://php.net/array_change_key_case in terms of
replacing elements with colliding keys.
Signature:
array array_change_keys ( array $input, callback $callback )
Reproduce code:
---------------
<?php
$a = array(
'peter' => 'm, 71',
'paul' => 'm, 72',
'mary' => 'f, 73'
);
$b = array_change_keys($a, 'strlen');
Expected result:
----------------
$b === array(
5 => 'm, 71',
4 => 'f, 73'
)
('paul' was overridden by the element 'mary' which resulted in the same key
name)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48543&edit=1