Fix dol_sort_array for objects

This commit is contained in:
Laurent Destailleur
2019-05-16 12:25:14 +02:00
parent bdb467b17a
commit 2d0b3b7b23

View File

@@ -6585,7 +6585,7 @@ function dol_htmloutput_errors($mesgstring = '', $mesgarray = array(), $keepembe
* or descending output and uses optionally natural case insensitive sorting (which
* can be optionally case sensitive as well).
*
* @param array $array Array to sort (array of array('key','otherkey1','otherkey2'...))
* @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), 0=use "standard" sort (asort)
@@ -6604,7 +6604,17 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen
if ($sizearray>0)
{
$temp = array();
foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
foreach(array_keys($array) as $key)
{
if (is_object($array[$key]))
{
$temp[$key]=$array[$key]->$index;
}
else
{
$temp[$key]=$array[$key][$index];
}
}
if (! $natsort) {
($order=='asc') ? asort($temp) : arsort($temp);