Re: Re: PHP 4.0 Bug #5730 Updated: sort and rsort are not 'opposites'
| From: | Stanislav Malyshev | Date: | Sun, 23 Jul 2000 11:35:20 +0000 |
| Subject: | Re: Re: PHP 4.0 Bug #5730 Updated: sort and rsort are not 'opposites' | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-25563@lists.php.net to get a copy of this message | ||
j>> gives
j>> 0 01 1 2 02
j>>
j>> this seems to be neither string or numeric, although I guess you could
j>> ague that it is numeric.
There's no point to argue. It is numeric. First goes 0, then 1 (twice),
then 2 (twice).
j>> But in the first example, the rules for sorting don't seem to be clear
j>> from looking at the result, which is why I called it random.
It is not random. PHP tries to convert all keys to numbers. This is
standard behaviour for almost every array operation in PHP.
j>> However, I would expect the results from sort and rsort to be
j>> symmetric... which they aren't.
Well, in fact nobody promised you this. When you get sort with duplicates
(i.e., keys having same sort value), you won't get sort and rsort
symmetric.
j>> Using SORT_STRING in the above two examples gives:
j>> 0 01 02 1 2
j>> 2 1 02 01 0
j>>
j>> which is clearly string sorting.
Exactly.
--
Stanislav Malyshev stas@zend.com
+972-3-6139665