multibyte and multi-dimensional-array support, have fun!
<?php
define('ARRAY_KEY_FC_LOWERCASE', 25); define('ARRAY_KEY_FC_UPPERCASE', 20); define('ARRAY_KEY_UPPERCASE', 15); define('ARRAY_KEY_LOWERCASE', 10); define('ARRAY_KEY_USE_MULTIBYTE', true); function array_change_key_case_ext(array $array, $case = 10, $useMB = false, $mbEnc = 'UTF-8') {
$newArray = array();
if($useMB === false) {
$function = 'strToUpper'; switch($case) {
case 25:
if(!function_exists('lcfirst'))
$function = create_function('$input', '
return strToLower($input[0]) . substr($input, 1, (strLen($input) - 1));
');
else $function = 'lcfirst';
break;
case 20:
$function = 'ucfirst';
break;
case 10:
$function = 'strToLower';
}
} else {
switch($case) {
case 25:
$function = create_function('$input', '
return mb_strToLower(mb_substr($input, 0, 1, \'' . $mbEnc . '\')) .
mb_substr($input, 1, (mb_strlen($input, \'' . $mbEnc . '\') - 1), \'' . $mbEnc . '\');
');
break;
case 20:
$function = create_function('$input', '
return mb_strToUpper(mb_substr($input, 0, 1, \'' . $mbEnc . '\')) .
mb_substr($input, 1, (mb_strlen($input, \'' . $mbEnc . '\') - 1), \'' . $mbEnc . '\');
');
break;
case 15:
$function = create_function('$input', '
return mb_strToUpper($input, \'' . $mbEnc . '\');
');
break;
default: $function = create_function('$input', '
return mb_strToLower($input, \'' . $mbEnc . '\');
');
}
}
foreach($array as $key => $value) {
if(is_array($value)) $newArray[$function($key)] = array_change_key_case_ex($value, $case, $useMB);
elseif(is_string($key))
$newArray[$function($key)] = $value;
else $newArray[$key] = $value; } return $newArray;
}
?>