Voting

: seven minus two?
(Example: nine)

The Note You're Voting On

cm at gameswelt dot de
17 years ago
I just changed the code a little bit so you havent got a code that repeats itself.

<?php

function array_change_key_case_secure($array = array(), $case = CASE_UPPER){
$secure = array();
$functionWrap = array(CASE_UPPER => 'strtoupper',
CASE_LOWER => 'strtolower');

foreach(
$array as $key => $val){
if(isset(
$functionWrap[$key])){
$key = $functionWrap[$case]($key);
$secure[$key][] = $val;
} else {
die(
'Not a known Type');
}
}

foreach(
$secure as $key => $val){
if(
count($secure[$key]) == 1){
$secure[$key] = $val[0];
}
}

return
$secure;
}

$myArray = array('A' => 'Hello',
'B' => 'World',
'a' => 'how are you?');

print_r($myArray);
$myArray = array_change_key_case_secure($myArray);
print_r($myArray);

/*
Array
(
[A] => Hello
[B] => World
[a] => how are you?
)
Array
(
[A] => Array
(
[0] => Hello
[1] => how are you?
)

[B] => World
)
*/

<< Back to user notes page

To Top