array_map not working
Posted: Wed Aug 22, 2007 11:46 am
If string indexed array is given to array_map it returns numerically indexed array after applying the callback.See this codeBut this is giving
Its numarically indexed instead of string indexed.
But how can I make it string index with the same key as original ??
Code: Select all
<?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
?>See I've marked it bold.Array
(
[one] => HeLlO
[two] => Hi
)
Array
(
[0] => hello
[1] => hi
)
Its numarically indexed instead of string indexed.
But how can I make it string index with the same key as original ??