{"record":{"id":"b592f77fe17e0c58","repo":"yiisoft/yii2","slug":"argument-array-must-be-an-array-or-implement-trav","errorCode":null,"errorMessage":"Argument $array must be an array or implement Traversable","messagePattern":"Argument \\$array must be an array or implement Traversable","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseArrayHelper.php","lineNumber":1084,"sourceCode":"     * // [\n     * //     'A.0' => 1\n     * //     'A.1' => 2\n     * //     'B.C' => 1\n     * //     'B.D' => 2\n     * //     'E' => 1\n     * // ]\n     * ```\n     *\n     * @param array $array the input array to be flattened in terms of name-value pairs.\n     * @param string $separator the separator to use between keys. Defaults to '.'.\n     *\n     * @return array the flattened array.\n     * @throws InvalidArgumentException if `$array` is neither traversable nor an array.\n     */\n    public static function flatten($array, $separator = '.'): array\n    {\n        if (!static::isTraversable($array)) {\n            throw new InvalidArgumentException('Argument $array must be an array or implement Traversable');\n        }\n\n        $result = [];\n\n        foreach ($array as $key => $value) {\n            $newKey = $key;\n            if (is_array($value)) {\n                $flattenedArray = self::flatten($value, $separator);\n                foreach ($flattenedArray as $subKey => $subValue) {\n                    $result[$newKey . $separator . $subKey] = $subValue;\n                }\n            } else {\n                $result[$newKey] = $value;\n            }\n        }\n\n        return $result;\n    }","sourceCodeStart":1066,"sourceCodeEnd":1102,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseArrayHelper.php#L1066-L1102","documentation":"Error \"Argument $array must be an array or implement Traversable\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/helpers/BaseArrayHelper.php:1084 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"}