diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php index 2a15921243f..7b660419daf 100644 --- a/htdocs/accountancy/admin/categories.php +++ b/htdocs/accountancy/admin/categories.php @@ -182,7 +182,7 @@ if ((empty($action) || $action == 'display' || $action == 'delete') && $cat_id > } if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) { - $accountingcategory->lines_display = dol_sort_array($accountingcategory->lines_display, $sortfield, $sortorder, 1, 0, 1); + $accountingcategory->lines_display = dol_sort_array($accountingcategory->lines_display, $sortfield, $sortorder, -1, 0, 1); foreach ($accountingcategory->lines_display as $cpt) { print ''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index cc32224ff2b..85cb8a9cdfe 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8671,7 +8671,8 @@ function dol_htmloutput_errors($mesgstring = '', $mesgarray = array(), $keepembe * @param array $array Array to sort (array of array('key1'=>val1,'key2'=>val2,'key3'...) or array of objects) * @param string $index Key in array to use for sorting criteria * @param int $order Sort order ('asc' or 'desc') - * @param int $natsort 1=use "natural" sort (natsort) for a search criteria thats is strings or unknown, 0=use "standard" sort (asort) for numbers + * @param int $natsort If values are strings (I said value not type): 0=Use alphabetical order, 1=use "natural" sort (natsort) + * If values are numeric (I said value not type): 0=Use numeric order (even if type is string) so use a "natural" sort, 1=use "natural" sort too (same than 0), -1=Force alphabetical order * @param int $case_sensitive 1=sort is case sensitive, 0=not case sensitive * @param int $keepindex If 0 and index key of array to sort is a numeric, than index will be rewrote. If 1 or index key is not numeric, key for index is kept after sorting. * @return array Sorted array @@ -8691,9 +8692,12 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen } else { $temp[$key] = empty($array[$key][$index]) ? 0 : $array[$key][$index]; } + if ($natsort == -1) { + $temp[$key] = '___'.$temp[$key]; // We add a string at begin of value to force an alpha order when using asort. + } } - if (!$natsort) { + if (empty($natsort) || $natsort == -1) { if ($order == 'asc') { asort($temp); } else {