note 23101 added to function.uksort
| From: | baatsaamNO_SPAM at hotmail dot com | Date: | Tue, 09 Jul 2002 15:29:52 +0000 |
| Subject: | note 23101 added to function.uksort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32799@lists.php.net to get a copy of this message | ||
If you have an array such as:
$items = array(
'ABC' = array(
'price' = 123,
'desc' = 'asdf'
)
'DEF' = array(
'price' = 321,
'desc' = 'jkl'
)
);
...and want to sort by description, one way of doing it is:
-----------------
function sortItems($a, $b) {
global $items;
return strcasecmp($items[$a]['desc'], $items[$a]['desc']);
}
uksort($items, "sortItems");
-----------------
If there's a better way, please let me know. :)
--
http://www.php.net/manual/en/function.uksort.php
http://master.php.net/manage/user-notes.php?action=edit+23101
http://master.php.net/manage/user-notes.php?action=delete+23101
http://master.php.net/manage/user-notes.php?action=reject+23101