php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42382 array_map not working properly with string indexed array
Submitted: 2007-08-22 15:21 UTC Modified: 2007-08-22 18:37 UTC
From: neel dot get at gmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.2.3 OS: Debian Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: neel dot get at gmail dot com
New email:
PHP Version: OS:

 

 [2007-08-22 15:21 UTC] neel dot get at gmail dot com
Description:
------------
If string indexed array is given to array_map it returns numerically indexed array after applying the callback.
I am using PHP 5.2.1 on Debian Linux.

Reproduce code:
---------------
<?php
$r = array('one' => 'HeLlO', 'two' => 'Hi');
print_r($r);//Orgiginal array
$r = array_map('tst_it', $r, array(false));
function tst_it($r, $bool = false){
	if($bool){return strtoupper($r);}
	else{return strtolower($r);}
}
print_r($r);//Array after array_map
?>

Expected result:
----------------
Array
(
    [one] => HeLlO
    [two] => Hi
)
Array
(
    [one] => hello
    [two] => hi
)

Actual result:
--------------
Array
(
    [one] => HeLlO
    [two] => Hi
)
Array
(
    [0] => hello
    [1] => hi
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-22 15:39 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2007-08-22 16:42 UTC] neel dot basu dot z at gmail dot com
OK so is it a feature ??
 [2007-08-22 18:37 UTC] neel dot get at gmail dot com
Ok Thanks I messed up array_walk() with array_map(). Sorry for that
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 12:01:31 2024 UTC