function count_uc($str) {
preg_match_all('/[A-Z]/', $str, $matches);
return count($matches[0]);
}
$input = array(
'green', 'Green', 'yelLOW',
'php', 'Php', 'PHP', 'gREEN',
'blue', 'yellow', 'bLue', 'GREen'
);
$input=array_unique($input);
$keys=array_flip($input);
array_multisort(array_map("strtolower",$input),array_map("count_uc",$input),$keys);
$keys=array_flip(array_change_key_case($keys));
$output=array_intersect_key($input,$keys);
print_r( $output );
will return:
Array
(
[2] => yelLOW
[5] => PHP
[6] => gREEN
[9] => bLue
)