Edit report at http://bugs.php.net/bug.php?id=52917&edit=1
ID: 52917
User updated by: luis dot pessoa67 at ibest dot com dot br
Reported by: luis dot pessoa67 at ibest dot com dot br
Summary: Function to change case-key recursively
Status: Duplicate
Type: Feature/Change Request
Package: Arrays related
Operating System: Any
PHP Version: 5.3.3
Block user comment: N
New Comment:
- Yes Kalle! this is the best way. Tks.
- Tks for the warning aharvey. I saw the 31058 request code and get
improved mine to this:
function ack_r2(&$array, $case)
{
$array = array_change_key_case($array, $case);
foreach ($array as $key => $value) {
if ( is_array($value) ) {
ack_r2($array[$key], $case);
}
}
}
Previous Comments:
------------------------------------------------------------------------
[2010-09-24 10:27:22] [email protected]
Duplicate of request #31058.
------------------------------------------------------------------------
[2010-09-23 21:21:46] [email protected]
It might be worth adding a recursive version or flag to the
array_change_key_case() function
------------------------------------------------------------------------
[2010-09-23 20:53:41] luis dot pessoa67 at ibest dot com dot br
Description:
------------
Hi, I suggest to create in the next php versions a function similar to
array_change_key_case() but doing it recursevely. Bellow I put some
example to doing that and the results.
regards, Luis
Test script:
---------------
<?php
function arrKey2Lower(&$arrVals) {
foreach( $arrVals as $key => $item ) {
$key2 = strtolower($key);
if ( $key2 != $key) {
unset($arrVals[$key]);
$arrVals[$key2]=$item;
$key=$key2;
}
if ( is_array($item) ) { arrKey2Lower($arrValores[$key]); }
}
}
$arr = array('ID' => 1, 'NAME'=> 'Luis', 'Contact' => array('PHONE'
=> '3010-7148', 'E-MAIL' => '[email protected]') );
arrKey2Lower($arr);
var_dump($arr);
?>
Expected result:
----------------
array(3) {
["id"]=>
int(1)
["name"]=>
string(4) "Luis"
["contact"]=>
array(2) {
["phone"]=>
string(9) "3010-7148"
["e-mail"]=>
string(12) "[email protected]"
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52917&edit=1