|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62749 array_map should call callback with array index
Submitted: 2012-08-04 19:14 UTC Modified: 2012-08-05 20:22 UTC
From: gmblar+php at gmail dot com Assigned:
Status: Wont fix Package: Arrays related
PHP Version: 5.4.5 OS: MacOSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gmblar+php at gmail dot com
New email:
PHP Version: OS:


 [2012-08-04 19:14 UTC] gmblar+php at gmail dot com
Add current array index as second argument to the callback of array_map

Test script:

$array = array(
    'foo' => 23,
    'bar' => 42

$result = array_map(function() {
    return implode(':', func_get_args());
}, $array);


Expected result:
array(2) {
  string(2) "23:foo"
  string(2) "42:foo"

Actual result:
array(2) {
  string(2) "23"
  string(2) "42"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-04 19:19 UTC] gmblar+php at gmail dot com
Correct expected result:
array(2) {
  string(2) "23:foo"
  string(2) "42:bar"
 [2012-08-05 20:08 UTC] ajf at ajf dot me
Just do array_map($func, $array, array_keys($array));
 [2012-08-05 20:22 UTC]
Changing this would break any app currently using array_map() and the workaround 
is trivial.
 [2012-08-05 20:22 UTC]
-Status: Open +Status: Wont fix
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 00:01:28 2024 UTC