php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #43612 array_map behaviour with string keys undocumented
Submitted: 2007-12-16 23:08 UTC Modified: 2008-01-20 15:04 UTC
From: nicholsr@php.net Assigned: nicholsr (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
 [2007-12-16 23:08 UTC] nicholsr@php.net
Description:
------------
The behaviour of array_map for string keys is not documented.

If the array argument  contains string keys then the returned array will contain string keys if exactly one array is passed. If more than one argument is passed then the returned array always has integer keys.

The following code demonstrates: 

$ cat 1.php
<?php
$arr = array("stringkey" => "value");
function cb1 ($a) {return array ($a);};
function cb2 ($a,$b) {return array ($a,$b);};
var_dump( array_map("cb1", $arr));
var_dump( array_map("cb2", $arr,$arr));
var_dump( array_map(null,  $arr));
var_dump( array_map(null, $arr, $arr));
?>
 
array(1) {
  ["stringkey"]=>
  array(1) {
    [0]=>
    string(5) "value"
  }
}
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(5) "value"
    [1]=>
    string(5) "value"
  }
}
array(1) {
  ["stringkey"]=>
  string(5) "value"
}
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(5) "value"
    [1]=>
    string(5) "value"
  }
}

 


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-07 19:48 UTC] bjori@php.net
You have the karma to fix it yourself... :)
 [2008-01-20 15:04 UTC] nicholsr@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 23:00:01 2026 UTC