{"record":{"id":"802387580123ec18","repo":"yiisoft/yii2","slug":"the-length-of-sortflag-parameter-must-be-the-same","errorCode":null,"errorMessage":"The length of $sortFlag parameter must be the same as that of $keys.","messagePattern":"The length of \\$sortFlag parameter must be the same as that of \\$keys\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseArrayHelper.php","lineNumber":683,"sourceCode":"     * @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;\n        $args[] = SORT_NUMERIC;\n\n        $args[] = &$array;\n        call_user_func_array('array_multisort', $args);\n    }","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseArrayHelper.php#L665-L701","documentation":"Error \"The length of $sortFlag parameter must be the same as that of $keys.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/helpers/BaseArrayHelper.php:683 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"}