note 54867 added to function.array-multisort
| From: | AlberT at SuperAlberT dot it | Date: | Mon, 18 Jul 2005 13:59:39 +0000 |
| Subject: | note 54867 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92112@lists.php.net to get a copy of this message | ||
a nice piece of code to do an "array_key_multi_sort()" is the following:
<?php
/**
* orders a multidimentional array on the base of a label-key
*
* @param $arr, the array to be ordered
* @param $l the "label" identifing the field
* @param $f the ordering function to be used,
* strnatcasecmp() by default
* @return TRUE on success, FALSE on failure.
*/
function array_key_multi_sort(&$arr, $l , $f='strnatcasecmp') {
return usort($arr, create_function('$a, $b', "return $f(\$a['$l'],
\$b['$l']);"));
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54867
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54867&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54867&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54867&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54867&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54867&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54867&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54867&report=yes
Search -- http://master.php.net/manage/user-notes.php