|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48543 Introduction of a substitute for array_change_key_case which takes a callback.
Submitted: 2009-06-13 11:21 UTC Modified: 2014-12-30 10:41 UTC
From: simon at stienen dot name Assigned:
Status: No Feedback Package: Arrays related
PHP Version: 5.3.0RC3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
26 + 45 = ?
Subscribe to this entry?

 [2009-06-13 11:21 UTC] simon at stienen dot name
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 in terms of replacing elements with colliding keys.

array array_change_keys  ( array $input, callback $callback )

Reproduce code:

$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)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-16 21:57 UTC]
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: Arrays related
 [2014-04-16 21:57 UTC]
Is this something you are still interested in?
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 09:01:28 2024 UTC