Hi,
I think it would sort it A B C D E F ... a b c d e f ....
But you can try to write a custom function to sort an array like this. I tested it with some random strings but you might need to test it further. As far as I can see it should work. This might be done in an easier way, but at least it should work.
<?PHP
function deepCompare($a,$b,$len) {
for ($i=0;$i<strlen($a);$i++) {
// walk through the strings
if ($a[$i] != $b[$i]) {
if (strtolower($a[$i]) != strtolower($b[$i])) {
// really different characters, so we mustn't care about the case
return (strtolower($a[$i]) < strtolower($b[$i])) ? -1 : 1;
}
// same character, different case
return ($a[$i]<$b[$i]) ? -1 : 1;
}
}
// one string is a substring of the other so we return a value depending on
// the length differences
return (strlen($a) < strlen($b)) ? -1 : 1;
}
function mySort($a,$b) {
if (strlen($a) != strlen($b))
{
// the strings are not of the same length, we must
// look deeper in them
return (strlen($a) < strlen($b)) ? deepCompare($a,$b,strlen($a)) : deepCompare($a,$b,strlen($b));
}
if (strtolower($a) != strtolower($b)) {
// same length but different strings so we should
// deepCompare them
return deepCompare($a,$b,strlen($a));
}
if ($a==$b) {
// same strings
return 0;
} else {
//same strings but different case
for ($i=0;$i<strlen($a);$i++) {
if ($a[$i] != $b[$i]) {
return ($a[$i] < $b[$i]) ? -1 : 1;
}
}
// this return shouldn't be needed but to make sure...
return 0;
}
}
$ar = array("A","Az","AZ","z","B","e","a","E","AzFEWF","azFEWF","efFd","Vds","eFFD","feegERD","Vdd","vDd","vvv");
usort($ar,"mySort");
for ($i=0;$i<count($ar);$i++) {
echo $ar[$i]."<br>\n";
}
?>