note 69091 added to function.sort
| From: | indigohaze at gmail dot com | Date: | Tue, 22 Aug 2006 20:40:18 +0000 |
| Subject: | note 69091 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116182@lists.php.net to get a copy of this message | ||
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?
----
Server IP: 64.71.164.2
Probable Submitter: 24.32.145.186
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/69091
Del: integrated -- https://master.php.net/note/delete/69091/integrated
Del: useless -- https://master.php.net/note/delete/69091/useless
Del: bad code -- https://master.php.net/note/delete/69091/bad+code
Del: spam -- https://master.php.net/note/delete/69091/spam
Del: non-english -- https://master.php.net/note/delete/69091/non-english
Del: in docs -- https://master.php.net/note/delete/69091/in+docs
Del: other reasons-- https://master.php.net/note/delete/69091
Reject -- https://master.php.net/note/reject/69091
Search -- https://master.php.net/manage/user-notes.php