This commit is contained in:
José González 2022-09-06 14:58:38 +02:00
parent 181b8d5d91
commit 0daeb906f1
1 changed files with 29 additions and 0 deletions

View File

@ -1216,6 +1216,35 @@ if ($autosearch) {
$result = array_merge($result, $result_server);
}
/**
* Auxiliar Ordenation function
*
* @param string $sort Direction of sort.
* @param string $sortField Field for perform the sorting.
*/
function arrayOutputSorting($sort, $sortField)
{
return function ($a, $b) use ($sort, $sortField) {
if ($sort === 'up') {
if (is_string($a[$sortField]) === true) {
return strnatcmp($a[$sortField], $b[$sortField]);
} else {
return ($a[$sortField] - $b[$sortField]);
}
} else {
if (is_string($a[$sortField]) === true) {
return strnatcmp($b[$sortField], $a[$sortField]);
} else {
return ($a[$sortField] + $b[$sortField]);
}
}
};
}
usort($result, arrayOutputSorting($sort, $sortField));
metaconsole_restore_db();
}