diff --git a/docs/guide/helper-array.md b/docs/guide/helper-array.md index 410fe5c198..698b8e795b 100644 --- a/docs/guide/helper-array.md +++ b/docs/guide/helper-array.md @@ -312,7 +312,8 @@ or an anonymous function like the following one: ```php ArrayHelper::multisort($data, function($item) { - return isset($item['age']) ? ['age', 'name'] : 'name'; + // sort by age if it exists or by name otherwise + return isset($item['age']) ? $item['age'] : $item['name']; }); ``` diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php index 9ad77c8e93..c5deb6f3de 100644 --- a/framework/helpers/BaseArrayHelper.php +++ b/framework/helpers/BaseArrayHelper.php @@ -648,9 +648,9 @@ class BaseArrayHelper throw new InvalidArgumentException('The length of $sortFlag parameter must be the same as that of $keys.'); } $args = []; - foreach ($keys as $i => $key) { + foreach ($keys as $i => $k) { $flag = $sortFlag[$i]; - $args[] = static::getColumn($array, $key); + $args[] = static::getColumn($array, $k); $args[] = $direction[$i]; $args[] = $flag; }