Reputation: 586
when sort an array with letter and number, like below:
$a = array(0, 1, 'a', 'A');
sort($a);
print_r($a);
the result confuse me like that:
Array ( [0] => a [1] => 0 [2] => A [3] => 1 )
why the '0' between in 'a' and 'A'?
Upvotes: 2
Views: 1126
Reputation: 719
When you do that, the numbers are converted to a string. Number character ASCII values come between the two cases.
The strings are converted to numbers. It takes any number characters at the beginning and drops everything else to compare, unless it finds '.','E', or 'e', which can be used for floating-point conversion. If it finds no numeric characters, it evaluates to zero.
Upvotes: 1