note 69091 rejected from function.sort by betz
| From: | betz@php.net | Date: | Wed, 23 Aug 2006 15:20:42 +0000 |
| Subject: | note 69091 rejected from function.sort by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116229@lists.php.net to get a copy of this message | ||
Note Submitter: indigohaze at gmail dot com
----
Odd sorting in 'mixed' arrays:
<?php
$flag = array ("a", "b", "c", "d", "1",
"5", "8", "r", "e", 2, 4, 6);
sort($flag);
print_r($flag);
?>
returns:
Array
(
[0] => 1
[1] => 2
[2] => 4
[3] => 5
[4] => 8
[5] => a
[6] => b
[7] => c
[8] => d
[9] => e
[10] => r
[11] => 6
)
while
<?php
$flag = array ("a", "b", "c", "d", "1",
"5", "8", "r", "e", 2, 4, 6);
sort($flag, SORT_NUMERIC);
print_r($flag);
?>
Returns:
Array
(
[0] => e
[1] => a
[2] => d
[3] => c
[4] => b
[5] => r
[6] => 1
[7] => 2
[8] => 4
[9] => 5
[10] => 6
[11] => 8
)
I find no reason for this... The inital example would indicate that sort() treats numeric string
data the same as int values, except that 6 is being placed at the end for no reason I understand...
When told to sort by Numeric Value it claims that "e" is a lower numeric value than
"a", "d" lower than "c" or "b"....
What's the criteria it's basing this off of?