{"id":"7a23830f98eab860","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-an-array-s-foun","errorCode":null,"errorMessage":"Array value for key [%s] must be an array, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be an array, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":87,"sourceCode":"    {\n        if (is_null(static::get($array, $key))) {\n            static::set($array, $key, $value);\n        }\n\n        return $array;\n    }\n\n    /**\n     * Get an array item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function array(ArrayAccess|array $array, string|int|null $key, ?array $default = null): array\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_array($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Array value for key [%s] must be an array, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Get a boolean item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function boolean(ArrayAccess|array $array, string|int|null $key, ?bool $default = null): bool\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_bool($value)) {\n            throw new InvalidArgumentException(","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/Arr.php#L69-L105","documentation":"Thrown by Arr::array() when the value resolved via Arr::get() (with dot notation) is not an array. The accessor exists to give a typed return, so any scalar, object, or null (missing key with no array default) fails.","triggerScenarios":"Calling Arr::array($config, 'database.options') when that key holds a scalar string, an object, or is missing and $default is null.","commonSituations":"Reading a config key whose schema changed; a key that is sometimes a string and sometimes a list; dot path that traverses into a scalar (e.g. 'db.name.extra').","solutions":["Pass an array default: Arr::array($config, 'database.options', []).","Validate with Arr::get() + is_array() before calling the typed accessor.","Fix the source data so the key always holds an array.","Use a more specific dot path that lands on the array node."],"exampleFix":"// before\n$opts = Arr::array($config, 'database.options');\n\n// after\n$opts = Arr::array($config, 'database.options', []);\n// or\n$v = Arr::get($config, 'database.options');\n$opts = is_array($v) ? $v : [];","handlingStrategy":"type-guard","validationCode":"$value = Arr::get($config, 'database.options');\nif (! is_array($value)) {\n    $value = [];\n}","typeGuard":"function arrayKeyIsArray(array $array, string $key): bool {\n    return is_array(Arr::get($array, $key));\n}","tryCatchPattern":"try {\n    $opts = Arr::array($config, 'database.options', []);\n} catch (\\InvalidArgumentException $e) {\n    $opts = [];\n}","preventionTips":["Pass an array default to Arr::array().","Validate with Arr::get() + is_array() for dynamic shapes.","Document the expected type of each config key."],"tags":["collections","arrays","type-mismatch","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}