Commit 3959b8db by Qiang Xue

Fixed test break.

parent 726a305b
...@@ -333,8 +333,8 @@ class BaseArrayHelper ...@@ -333,8 +333,8 @@ class BaseArrayHelper
* elements, a property name of the objects, or an anonymous function returning the values for comparison * elements, a property name of the objects, or an anonymous function returning the values for comparison
* purpose. The anonymous function signature should be: `function($item)`. * purpose. The anonymous function signature should be: `function($item)`.
* To sort by multiple keys, provide an array of keys here. * To sort by multiple keys, provide an array of keys here.
* @param boolean|array $descending whether to sort in descending or ascending order. When * @param integer|array $direction the sorting direction. It can be either `SORT_ASC` or `SORT_DESC`.
* sorting by multiple keys with different descending orders, use an array of descending flags. * When sorting by multiple keys with different sorting directions, use an array of sorting directions.
* @param integer|array $sortFlag the PHP sort flag. Valid values include * @param integer|array $sortFlag the PHP sort flag. Valid values include
* `SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`, `SORT_LOCALE_STRING`, `SORT_NATURAL` and `SORT_FLAG_CASE`. * `SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`, `SORT_LOCALE_STRING`, `SORT_NATURAL` and `SORT_FLAG_CASE`.
* Please refer to [PHP manual](http://php.net/manual/en/function.sort.php) * Please refer to [PHP manual](http://php.net/manual/en/function.sort.php)
...@@ -345,16 +345,16 @@ class BaseArrayHelper ...@@ -345,16 +345,16 @@ class BaseArrayHelper
* @throws InvalidParamException if the $descending or $sortFlag parameters do not have * @throws InvalidParamException if the $descending or $sortFlag parameters do not have
* correct number of elements as that of $key. * correct number of elements as that of $key.
*/ */
public static function multisort(&$array, $key, $descending = false, $sortFlag = SORT_REGULAR, $caseSensitive = true) public static function multisort(&$array, $key, $direction = SORT_ASC, $sortFlag = SORT_REGULAR, $caseSensitive = true)
{ {
$keys = is_array($key) ? $key : [$key]; $keys = is_array($key) ? $key : [$key];
if (empty($keys) || empty($array)) { if (empty($keys) || empty($array)) {
return; return;
} }
$n = count($keys); $n = count($keys);
if (is_scalar($descending)) { if (is_scalar($direction)) {
$descending = array_fill(0, $n, $descending); $direction = array_fill(0, $n, $direction);
} elseif (count($descending) !== $n) { } elseif (count($direction) !== $n) {
throw new InvalidParamException('The length of $descending parameter must be the same as that of $keys.'); throw new InvalidParamException('The length of $descending parameter must be the same as that of $keys.');
} }
if (is_scalar($sortFlag)) { if (is_scalar($sortFlag)) {
...@@ -377,7 +377,7 @@ class BaseArrayHelper ...@@ -377,7 +377,7 @@ class BaseArrayHelper
} else { } else {
$args[] = static::getColumn($array, $key); $args[] = static::getColumn($array, $key);
} }
$args[] = $descending[$i] ? SORT_DESC : SORT_ASC; $args[] = $direction;
$args[] = $flag; $args[] = $flag;
} }
$args[] = &$array; $args[] = &$array;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment