{"record":{"id":"87fe9c18fc694d78","repo":"yiisoft/yii2","slug":"the-length-of-direction-parameter-must-be-the-sam","errorCode":null,"errorMessage":"The length of $direction parameter must be the same as that of $keys.","messagePattern":"The length of \\$direction parameter must be the same as that of \\$keys\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseArrayHelper.php","lineNumber":678,"sourceCode":"     * When sorting by multiple keys with different sorting directions, use an array of sorting directions.\n     * @param int|array $sortFlag the PHP sort flag. Valid values include\n     * `SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`, `SORT_LOCALE_STRING`, `SORT_NATURAL` and `SORT_FLAG_CASE`.\n     * Please refer to [PHP manual](https://www.php.net/manual/en/function.sort.php)\n     * for more details. When sorting by multiple keys with different sort flags, use an array of sort flags.\n     * @throws InvalidArgumentException if the $direction or $sortFlag parameters do not have\n     * correct number of elements as that of $key.\n     */\n    public static function multisort(&$array, $key, $direction = SORT_ASC, $sortFlag = SORT_REGULAR)\n    {\n        $keys = is_array($key) ? $key : [$key];\n        if (empty($keys) || empty($array)) {\n            return;\n        }\n        $n = count($keys);\n        if (is_scalar($direction)) {\n            $direction = array_fill(0, $n, $direction);\n        } elseif (count($direction) !== $n) {\n            throw new InvalidArgumentException('The length of $direction parameter must be the same as that of $keys.');\n        }\n        if (is_scalar($sortFlag)) {\n            $sortFlag = array_fill(0, $n, $sortFlag);\n        } elseif (count($sortFlag) !== $n) {\n            throw new InvalidArgumentException('The length of $sortFlag parameter must be the same as that of $keys.');\n        }\n        $args = [];\n        foreach ($keys as $i => $k) {\n            $flag = $sortFlag[$i];\n            $args[] = static::getColumn($array, $k);\n            $args[] = $direction[$i];\n            $args[] = $flag;\n        }\n\n        // This fix is used for cases when main sorting specified by columns has equal values\n        // Without it it will lead to Fatal Error: Nesting level too deep - recursive dependency?\n        $args[] = range(1, count($array));\n        $args[] = SORT_ASC;","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseArrayHelper.php#L660-L696","documentation":"Error \"The length of $direction parameter must be the same as that of $keys.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/helpers/BaseArrayHelper.php:678 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}