protected static function _sort($a, $b, $sortby = null, $sortdir = null)
{
if (is_null($sortby)) {
$sortby = self::$_sortBy;
}
if (is_null($sortdir)) {
$sortdir = self::$_sortDir;
}
if (is_array($sortby)) {
if (!isset($a[$sortby[0]])) {
$a[$sortby[0]] = null;
}
if (!isset($b[$sortby[0]])) {
$b[$sortby[0]] = null;
}
if (!count($sortby)) {
return 0;
}
if ($a['sort_by'][$sortby[0]] > $b['sort_by'][$sortby[0]]) {
return $sortdir[0] ? -1 : 1;
}
if ($a['sort_by'][$sortby[0]] === $b['sort_by'][$sortby[0]]) {
array_shift($sortby);
array_shift($sortdir);
return self::_sort($a, $b, $sortby, $sortdir);
}
return $sortdir[0] ? 1 : -1;
}
$a_val = isset($a['sort_by'][$sortby]) ? $a['sort_by'][$sortby] : null;
$b_val = isset($b['sort_by'][$sortby]) ? $b['sort_by'][$sortby] : null;
// Take care of the simplest case first
if ($a_val === $b_val) {
return 0;
}
if ((is_numeric($a_val) || is_null($a_val)) && (is_numeric($b_val) || is_null($b_val))) {
// Numeric comparison
return (int) ($sortdir ? $b_val > $a_val : $a_val > $b_val);
}
// Some special case sorting
if (is_array($a_val) || is_array($b_val)) {
$a_val = implode('', $a_val);
$b_val = implode('', $b_val);
}
// String comparison
return $sortdir ? strcoll($b_val, $a_val) : strcoll($a_val, $b_val);
}