note 99349 added to function.uasort
| From: | twecsyzenhout at gmail dot com | Date: | Thu, 12 Aug 2010 10:36:01 +0000 |
| Subject: | note 99349 added to function.uasort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171596@lists.php.net to get a copy of this message | ||
Using usort and strcomp together to order an array by one of its keys has an odd effect: it returns
my array with fewer items in it than I put in.
The array in my case contains a list of tasks, and I want to order the rows in the array by the
field 'displayorder', which is a number but which I want to be sorted in alphabetical
manner.
function treeSort($a, $b) {
return strcmp(strval($a['displayOrder']), strval($b['displayOrder']));
}
usort($tree, "treeSort");
There are nine rows, but I only get six of them back. Those six are nicely sorted, by the way.
----
Server IP: 69.147.83.197
Probable Submitter: 77.251.206.203
----
Manual Page -- http://www.php.net/manual/en/function.uasort.php
Edit -- https://master.php.net/note/edit/99349
Del: integrated -- https://master.php.net/note/delete/99349/integrated
Del: useless -- https://master.php.net/note/delete/99349/useless
Del: bad code -- https://master.php.net/note/delete/99349/bad+code
Del: spam -- https://master.php.net/note/delete/99349/spam
Del: non-english -- https://master.php.net/note/delete/99349/non-english
Del: in docs -- https://master.php.net/note/delete/99349/in+docs
Del: other reasons-- https://master.php.net/note/delete/99349
Reject -- https://master.php.net/note/reject/99349
Search -- https://master.php.net/manage/user-notes.php