mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-03 23:52:24 +01:00
NEW dol_sort_array can sort on alphabetical order even if val is num
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user