#43612 [Opn->Asn]: array_map behaviour with string keys undocumented

From: Date: Mon, 07 Jan 2008 19:48:47 +0000
Subject: #43612 [Opn->Asn]: array_map behaviour with string keys undocumented
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-416@lists.php.net to get a copy of this message
ID: 43612 Updated by: bjori@php.net Reported By: nicholsr@php.net -Status: Open +Status: Assigned Bug Type: Documentation problem Operating System: all PHP Version: Irrelevant -Assigned To: +Assigned To: nicholsr New Comment: You have the karma to fix it yourself... :) Previous Comments: ------------------------------------------------------------------------ [2007-12-16 23:08:19] 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" } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43612&edit=1

« previous php.doc.bugs (#416) next »