note 65863 modified in language.operators.comparison by danbrown

From: Date: Thu, 18 Jun 2009 14:08:42 +0000
Subject: note 65863 modified in language.operators.comparison by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157074@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... --was-- 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... http://php.net/manual/en/language.operators.comparison.php

« previous php.notes (#157074) next »