note 60744 deleted from function.array-change-key-case by didou
| From: | didou@php.net | Date: | Sat, 27 Jan 2007 00:09:38 +0000 |
| Subject: | note 60744 deleted from function.array-change-key-case by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122250@lists.php.net to get a copy of this message | ||
Note Submitter: cmorell184 at comcast dot net
----
The following function will do a switch case case on your array keys (foobar would become FoObAr)
Not sure if it will come in handy, but it may
<?php
function array_case_switch($array) {
$curr = 1;
foreach ($array as $key=>$value) {
$newkey = "";
for ($i = 0; $i < strlen($key); $i++) {
if ($curr % 2) {
$newkey .= ($i % 2) ? strtolower(substr($key,$i,1)) : strtoupper(substr($key,$i,1));
} else {
$newkey .= ($i % 2) ? strtoupper(substr($key,$i,1)) : strtolower(substr($key,$i,1));
}
}
$newarray[$newkey] = $value;
$curr++;
}
return $newarray;
}
?>