note 106232 deleted from function.array-change-key-case by danbrown
| From: | danbrown@php.net | Date: | Thu, 20 Oct 2011 17:07:01 +0000 |
| Subject: | note 106232 deleted from function.array-change-key-case by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184025@lists.php.net to get a copy of this message | ||
Note Submitter: jothi at appleg dot net
----
Script to change case of sub-arrays keys to lower . It works well for me. hope it helps.
<?php
$array=array("First"=>"val1","SecoNd"=>"val2",
"third"=>array("third-INner1"=>"val3.1"),
"fourth"=>array("FouthINNer1"=>"val4.1","FourthINNER2"=>"val4.2"));
print_r($array);
$key=array_keys($array);
foreach($key as $ki)
{
$klower=strtolower($ki);
$val=$array[$ki];
if(is_array($val))
{
foreach($val as $kinner=>$vinner)
{
$tl=strtolower($kinner);
unset($val[$kinner]);
$val[$tl]=$vinner;
}
}
unset($array[$ki]);
$array[$klower]=$val;
}
echo "<br> After Changing Key to-LowerCase : <br>";
print_r($array);
?>