intval($arr_b[$i])) { return 1; } elseif (intval($arr_a[$i]) < intval($arr_b[$i])) { return -1; } } else { $cmp = strcmp(strval($arr_a[$i]), strval($arr_b[$i])); if (($cmp > 0) || ($cmp < 0)) { return $cmp; } } } if (cacti_count($arr_a) < cacti_count($arr_b)) { return 1; } elseif (cacti_count($arr_a) > cacti_count($arr_b)) { return -1; } return 0; } /* usort_numeric - sorts two values numerically (ie. 1, 34, 36, 76) @arg $a - the first string to compare @arg $b - the second string to compare @returns - '1' if $a is greater than $b, '-1' if $a is less than $b, or '0' if $b is equal to $b */ function usort_numeric($a, $b) { if (intval($a) > intval($b)) { return 1; } elseif (intval($a) < intval($b)) { return -1; } else { return 0; } } /* usort_alphabetic - sorts two values alphabetically (ie. ab, by, ef, xy) @arg $a - the first string to compare @arg $b - the second string to compare @returns - '1' if $a is greater than $b, '-1' if $a is less than $b, or '0' if $b is equal to $b */ function usort_alphabetic($a, $b) { return strcmp($a, $b); } /* usort_natural - sorts two values naturally (ie. ab1, ab2, ab7, ab10, ab20) @arg $a - the first string to compare @arg $b - the second string to compare @returns - '1' if $a is greater than $b, '-1' if $a is less than $b, or '0' if $b is equal to $b */ function usort_natural($a, $b) { return strnatcmp($a, $b); } /* sort_by_subkey - takes the list of templates and perform a final sort @returns - (array) an array of sorted templates */ function sort_by_subkey(&$array, $subkey, $sort = SORT_ASC) { $keys = array(); foreach ($array as $subarray) { $keys[] = $subarray[$subkey]; } array_multisort($keys, $sort, $array); }