mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 06:13:58 -07:00
Merge pull request #518 from torrentpier/fixed-array-multi-sorting
Fixed array multi sorting
This commit is contained in:
commit
0b72f999fa
2 changed files with 8 additions and 40 deletions
|
@ -202,7 +202,7 @@ if ($mode == 'extensions') {
|
||||||
DB()->sql_freeresult($result);
|
DB()->sql_freeresult($result);
|
||||||
|
|
||||||
if ($num_extension_row > 0) {
|
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++) {
|
for ($i = 0; $i < $num_extension_row; $i++) {
|
||||||
if ($submit) {
|
if ($submit) {
|
||||||
|
|
|
@ -82,47 +82,15 @@ function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
|
||||||
/**
|
/**
|
||||||
* Sort multi-dimensional array
|
* Sort multi-dimensional array
|
||||||
*
|
*
|
||||||
* @param $sort_array
|
* @param array $sort_array
|
||||||
* @param $key
|
* @param string|int $key
|
||||||
* @param $sort_order
|
* @param int $sort_order
|
||||||
* @param int $pre_string_sort
|
* @return array
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
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;
|
$keys = array_column($sort_array, $key);
|
||||||
|
array_multisort($keys, $sort_order, $sort_array);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sort_array;
|
return $sort_array;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue