Edit report at https://bugs.php.net/bug.php?id=62749&edit=1

 ID:                 62749
 Updated by:         ras...@php.net
 Reported by:        gmblar+php at gmail dot com
 Summary:            array_map should call callback with array index
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   MacOSX
 PHP Version:        5.4.5
 Block user comment: N
 Private report:     N

 New Comment:

Changing this would break any app currently using array_map() and the 
workaround 
is trivial.


Previous Comments:
------------------------------------------------------------------------
[2012-08-05 20:08:09] ajf at ajf dot me

Just do array_map($func, $array, array_keys($array));

------------------------------------------------------------------------
[2012-08-04 19:19:16] gmblar+php at gmail dot com

Correct expected result:
----------------
array(2) {
  ["foo"]=>
  string(2) "23:foo"
  ["bar"]=>
  string(2) "42:bar"
}

------------------------------------------------------------------------
[2012-08-04 19:14:23] gmblar+php at gmail dot com

Description:
------------
Add current array index as second argument to the callback of array_map

Test script:
---------------
<?php

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

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

var_dump($result);




Expected result:
----------------
array(2) {
  ["foo"]=>
  string(2) "23:foo"
  ["bar"]=>
  string(2) "42:foo"
}


Actual result:
--------------
array(2) {
  ["foo"]=>
  string(2) "23"
  ["bar"]=>
  string(2) "42"
}



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62749&edit=1

Reply via email to