note 63715 added to function.sort
| From: | Emiliyan at ServicesBG dot Com | Date: | Wed, 29 Mar 2006 03:41:07 +0000 |
| Subject: | note 63715 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106901@lists.php.net to get a copy of this message | ||
#This is a function that will sort an array...
function sort_by($array, $keyname = null, $sortby) {
$myarray = $inarray = array();
# First store the keyvalues in a seperate array
foreach ($array as $i => $befree) {
$myarray[$i] = $array[$i][$keyname];
}
# Sort the new array by
switch ($sortby) {
case 'asc':
# Sort an array and maintain index association...
asort($myarray);
break;
case 'arsort':
# Sort an array in reverse order and maintain index association
arsort($myarray);
break;
case 'natcasesor':
# Sort an array using a case insensitive "natural order" algorithm
natcasesort($myarray);
break;
}
# Rebuild the old array
foreach ( $myarray as $key=> $befree) {
$inarray[$key] = $array[$key];
}
return $inarray;
}
sort_by(); example...
$info = sort_by($myarray, 'name', $use = 'asc');
print_r($info);
----
Server IP: 195.149.248.161
Probable Submitter: 212.104.112.223
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- http://master.php.net/note/edit/63715
Del: integrated -- http://master.php.net/note/delete/63715/integrated
Del: useless -- http://master.php.net/note/delete/63715/useless
Del: bad code -- http://master.php.net/note/delete/63715/bad+code
Del: spam -- http://master.php.net/note/delete/63715/spam
Del: non-english -- http://master.php.net/note/delete/63715/non-english
Del: in docs -- http://master.php.net/note/delete/63715/in+docs
Del: other reasons-- http://master.php.net/note/delete/63715
Reject -- http://master.php.net/note/reject/63715
Search -- http://master.php.net/manage/user-notes.php