#21728 [NEW]: Additional (kindly weird example) for sort()
| From: | andrey@php.net | Date: | Sat, 18 Jan 2003 16:26:27 +0000 |
| Subject: | #21728 [NEW]: Additional (kindly weird example) for sort() | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969351007@lists.php.net to get a copy of this message | ||
From: andrey@php.net
Operating system: All
PHP version: 4.3.0
PHP Bug Type: Documentation problem
Bug description: Additional (kindly weird example) for sort()
Today I closed bug #21444. The user has to master the type juggling to
know the expected output. I think that it is good idea to add it's example
as comprehensive one.
The script goes here (the explanation is after it) :
<?php
$arr1 =
array("a","b","c","d","4",5,4,"true","TRUE",true);
sort($arr1);
var_dump($arr1);
?>
The output is :
array(10) {
[0]=>
bool(true)
[1]=>
int(4)
[2]=>
string(1) "4"
[3]=>
string(4) "TRUE"
[4]=>
string(1) "a"
[5]=>
string(1) "b"
[6]=>
string(1) "c"
[7]=>
string(1) "d"
[8]=>
string(4) "true"
[9]=>
int(5)
}
It may look strange - why (int)5 is after all the strings. This is
because "4" is lower than (int) 5, "4" is before "true" and
"true" is
before 5. The first 2 are obvious, the third one is not. But it is ok.
It's better not to mix types in the array. If 5 is changed to "5" then
"5" goes right after "4".
Thanks
--
Edit bug report at http://bugs.php.net/?id=21728&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=21728&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=21728&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=21728&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=21728&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=21728&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=21728&r=support
Expected behavior: http://bugs.php.net/fix.php?id=21728&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=21728&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=21728&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=21728&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21728&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=21728&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=21728&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=21728&r=gnused