I'm trying to sort an array alphabetically with uppercase letters first in the array
Example:
array(7) {
["H"]=>
int(1)
["W"]=>
int(1)
["e"]=>
int(1)
["l"]=>
int(3)
["o"]=>
int(2)
["r"]=>
int(1)
["d"]=>
int(1)
}
My code doesn't sort with uppercase letters, only alphabetically
Here is my code:
function count_char($str) {
$chars = str_split($str);
$char_counter = Array();
foreach($chars as $char)
if ((ord($char) >= 65 && ord($char) <= 90) ||
(ord($char) >= 97 && ord($char) <= 122)) {
if(!isset($char_counter[$char])) $char_counter[$char] = 1;
else $char_counter[$char] += 1;
}
return $char_counter;
}
var_dump(count_char("Hello World"));
My desired output is $str, I would like alphabetizing the uppers, then alphabetizing the lowers