note 102701 added to function.usort
| From: | CuongHuyTo at osu1 dot php dot net | Date: | Tue, 01 Mar 2011 13:54:54 +0000 |
| Subject: | note 102701 added to function.usort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177435@lists.php.net to get a copy of this message | ||
Probably a bug or an undocumented feature: usort() sorts your list even if you don't want to.
Detail:
If you call usort($your_list, "your_call_back_function"), where inside the
your_call_back_function() you return 0 immediately, then you would expect $your_list to be
unchanged. But in fact it is changed.
Code:
<?php
function your_call_back_function($left, $right){
return 0;
}
$your_list = array(1, 3, 2);
usort($your_list, "your_call_back_function");
print_r($your_list);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 80.113.160.213
----
Manual Page -- http://www.php.net/manual/en/function.usort.php
Edit -- https://master.php.net/note/edit/102701
Del: integrated -- https://master.php.net/note/delete/102701/integrated
Del: useless -- https://master.php.net/note/delete/102701/useless
Del: bad code -- https://master.php.net/note/delete/102701/bad+code
Del: spam -- https://master.php.net/note/delete/102701/spam
Del: non-english -- https://master.php.net/note/delete/102701/non-english
Del: in docs -- https://master.php.net/note/delete/102701/in+docs
Del: other reasons-- https://master.php.net/note/delete/102701
Reject -- https://master.php.net/note/reject/102701
Search -- https://master.php.net/manage/user-notes.php