note 65863 added to language.operators.comparison
| From: | adam at caucho dot com | Date: | Tue, 09 May 2006 05:49:59 +0000 |
| Subject: | note 65863 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110928@lists.php.net to get a copy of this message | ||
Note: according to the spec, PHP's comparison
operators are not transitive. For example,
the following are all true in PHP5:
"11" < "a" < 2 < "11"
As a result, the outcome of sorting an array
depends on the order the elements appear
in the pre-sort array. The following code will
dump out two arrays with *different* orderings:
<?php
$a = array(2, "a", "11", 2);
$b = array(2, "11", "a", 2);
sort($a);
var_dump($a);
sort($b);
var_dump($b);
?>
This is not a bug report -- given the spec on
this documentation page, what PHP does is
"correct". But that may not be what was
intended...
----
Server IP: 66.163.161.117
Probable Submitter: 66.159.230.136
----
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/language.operators.comparison.php
Edit -- http://master.php.net/note/edit/65863
Del: integrated -- http://master.php.net/note/delete/65863/integrated
Del: useless -- http://master.php.net/note/delete/65863/useless
Del: bad code -- http://master.php.net/note/delete/65863/bad+code
Del: spam -- http://master.php.net/note/delete/65863/spam
Del: non-english -- http://master.php.net/note/delete/65863/non-english
Del: in docs -- http://master.php.net/note/delete/65863/in+docs
Del: other reasons-- http://master.php.net/note/delete/65863
Reject -- http://master.php.net/note/reject/65863
Search -- http://master.php.net/manage/user-notes.php