note 86654 rejected from function.uksort by thiago
| From: | thiago@php.net | Date: | Tue, 28 Oct 2008 17:12:57 +0000 |
| Subject: | note 86654 rejected from function.uksort by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145887@lists.php.net to get a copy of this message | ||
Note Submitter: ian dot greenleaf at gee mail dot com
----
skippy at zuavra dot net noted that calling uksort with a callback that always returns 0
doesn't leave the elements in place. In fact, it seems to reverse the ordering of the array!
This doesn't seem like desirable behavior...
<?php
function always_tie() {
return 0;
}
$myarray = array(3, 5, 1, 7);
print_r($myarray); // 3,5,1,7
uksort($myarray, 'always_tie');
print_r($myarray); // 7,1,5,3
uksort($myarray, 'always_tie');
print_r($myarray); // 3,5,1,7
?>