From d474133cd4b2267b8fbfbf4d769448d5ba03f5f1 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Wed, 15 May 2013 10:12:15 +0300 Subject: [PATCH] Make multisort compatible with Sort Test code ```php $orders = $this->getSort()->getOrders(); ArrayHelper::multisort($data, array_keys($orders), array_values($orders)); ``` --- yii/helpers/base/ArrayHelper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yii/helpers/base/ArrayHelper.php b/yii/helpers/base/ArrayHelper.php index c70e63d..afe21cf 100644 --- a/yii/helpers/base/ArrayHelper.php +++ b/yii/helpers/base/ArrayHelper.php @@ -275,16 +275,16 @@ class ArrayHelper * @throws InvalidParamException if the $ascending or $sortFlag parameters do not have * correct number of elements as that of $key. */ - public static function multisort(&$array, $key, $ascending = true, $sortFlag = SORT_REGULAR, $caseSensitive = true) + public static function multisort(&$array, $key, $descending = false, $sortFlag = SORT_REGULAR, $caseSensitive = true) { $keys = is_array($key) ? $key : array($key); if (empty($keys) || empty($array)) { return; } $n = count($keys); - if (is_scalar($ascending)) { - $ascending = array_fill(0, $n, $ascending); - } elseif (count($ascending) !== $n) { + if (is_scalar($descending)) { + $descending = array_fill(0, $n, $descending); + } elseif (count($descending) !== $n) { throw new InvalidParamException('The length of $ascending parameter must be the same as that of $keys.'); } if (is_scalar($sortFlag)) { @@ -315,7 +315,7 @@ class ArrayHelper } else { $args[] = static::getColumn($array, $key); } - $args[] = $ascending[$i] ? SORT_ASC : SORT_DESC; + $args[] = $descending[$i] ? SORT_DESC : SORT_ASC; $args[] = $flag; } $args[] = &$array;