mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 10:37:30 -07:00
Fixed array multi sorting
This commit is contained in:
parent
65bdac8887
commit
983d364845
2 changed files with 8 additions and 40 deletions
|
@ -202,7 +202,7 @@ if ($mode == 'extensions') {
|
|||
DB()->sql_freeresult($result);
|
||||
|
||||
if ($num_extension_row > 0) {
|
||||
$extension_row = sort_multi_array($extension_row, 'group_name', 'ASC');
|
||||
$extension_row = sort_multi_array($extension_row, 'extension');
|
||||
|
||||
for ($i = 0; $i < $num_extension_row; $i++) {
|
||||
if ($submit) {
|
||||
|
|
|
@ -82,47 +82,15 @@ function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
|
|||
/**
|
||||
* Sort multi-dimensional array
|
||||
*
|
||||
* @param $sort_array
|
||||
* @param $key
|
||||
* @param $sort_order
|
||||
* @param int $pre_string_sort
|
||||
* @return mixed
|
||||
* @param array $sort_array
|
||||
* @param string|int $key
|
||||
* @param int $sort_order
|
||||
* @return array
|
||||
*/
|
||||
function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0)
|
||||
function sort_multi_array(array $sort_array, $key, int $sort_order = SORT_ASC): array
|
||||
{
|
||||
$last_element = count($sort_array) - 1;
|
||||
|
||||
if (!$pre_string_sort) {
|
||||
$string_sort = (!is_numeric(@$sort_array[$last_element - 1][$key])) ? true : false;
|
||||
} else {
|
||||
$string_sort = $pre_string_sort;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $last_element; $i++) {
|
||||
$num_iterations = $last_element - $i;
|
||||
|
||||
foreach ($sort_array as $j => $jValue) {
|
||||
// do checks based on key
|
||||
$switch = false;
|
||||
if (!$string_sort) {
|
||||
if (($sort_order == 'DESC' && (int)(@$sort_array[$j][$key]) < (int)(@$sort_array[$j + 1][$key])) ||
|
||||
($sort_order == 'ASC' && (int)(@$sort_array[$j][$key]) > (int)(@$sort_array[$j + 1][$key]))) {
|
||||
$switch = true;
|
||||
}
|
||||
} else {
|
||||
if (($sort_order == 'DESC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) < 0) ||
|
||||
($sort_order == 'ASC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) > 0)) {
|
||||
$switch = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($switch) {
|
||||
$temp = $jValue;
|
||||
$sort_array[$j] = $sort_array[$j + 1];
|
||||
$sort_array[$j + 1] = $temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
$keys = array_column($sort_array, $key);
|
||||
array_multisort($keys, $sort_order, $sort_array);
|
||||
|
||||
return $sort_array;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue