note 35833 added to function.uasort
| From: | cablehead at rn2 dot php dot net | Date: | Tue, 16 Sep 2003 13:08:40 +0000 |
| Subject: | note 35833 added to function.uasort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56569@lists.php.net to get a copy of this message | ||
dholmes we turned your masort function into a smarty plugin:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1079
messju contributed the following performance improvements.
function masort(&$data, $sortby)
{
static $sort_funcs = array();
if (empty($sort_funcs[$sortby])) {
$code = "\$c=0;";
foreach (split(',', $sortby) as $key) {
$code .= "if ( (\$c = strcasecmp(\$a['$key'],\$b['$key'])) != 0
) return \$c;\n";
}
$code .= 'return $c;';
$sort_func = $sort_funcs[$sortby] = create_function('$a, $b', $code);
} else {
$sort_func = $sort_funcs[$sortby];
}
$sort_func = $sort_funcs[$sortby];
uasort($data, $sort_func);
}
thank you for the cool function!
----
Manual Page -- http://www.php.net/manual/en/function.uasort.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35833
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35833&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35833&report=yes