note 38957 added to function.array-multisort
| From: | marin at xit dot nl | Date: | Tue, 13 Jan 2004 10:55:00 +0000 |
| Subject: | note 38957 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63402@lists.php.net to get a copy of this message | ||
I needed a function to sort multi dimensional arrays, but case in-sensitive. I used Ichier function
with a little modification:
function array_csort() { //coded by Ichier2003
$args = func_get_args();
$marray = array_shift($args);
$msortline = "return(array_multisort(";
foreach ($args as $arg) {
$i++;
if (is_string($arg)) {
foreach ($marray as $row) {
// added by Marin for case in-sensitive search
$a = strtoupper($row[$arg]);
$sortarr[$i][] = $a;
}
} else {
$sortarr[$i] = $arg;
}
$msortline .= "\$sortarr[".$i."],";
}
$msortline .= "\$marray));";
eval($msortline);
return $marray;
}
For usage of this function, see Ichier's post somewhere below
Thanks Ichier, a superb function indeed!
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38957
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38957&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38957&report=yes
Search -- http://master.php.net/manage/user-notes.php