{"record":{"id":"706795f9c320d8ea","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-an-integer-s-fo","errorCode":null,"errorMessage":"Array value for key [%s] must be an integer, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be an integer, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":648,"sourceCode":"            if ($callback($value, $key)) {\n                return true;\n            }\n        }\n\n        return false;\n    }\n\n    /**\n     * Get an integer item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function integer(ArrayAccess|array $array, string|int|null $key, ?int $default = null): int\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_int($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Array value for key [%s] must be an integer, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Determines if an array is associative.\n     *\n     * An array is \"associative\" if it doesn't have sequential numerical keys beginning with zero.\n     *\n     * @param  array  $array\n     * @return ($array is list ? false : true)\n     */\n    public static function isAssoc(array $array)\n    {\n        return ! array_is_list($array);","sourceCodeStart":630,"sourceCodeEnd":666,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Arr.php#L630-L666","documentation":"Thrown by Arr::integer() when the resolved dot-notation value is not an int. is_int() is strict: a numeric string '42' or a float 42.0 will fail (unlike the Cache::integer path which coerces).","triggerScenarios":"Calling Arr::integer($data, 'key') where the value is a string digit, float, bool, null, or array.","commonSituations":"JSON/API input where numbers arrive as strings ('\"id\":123' decoded as string); query params that are always strings; missing keys.","solutions":["Pass an int default: Arr::integer($data, 'key', 0).","Cast the source: (int) $data['count'] before lookup.","Use Arr::get() plus (int) cast if string-number inputs are valid."],"exampleFix":"// before\n$id = Arr::integer($input, 'id'); // '123' string throws\n// after\n$id = Arr::integer($input, 'id', 0);","handlingStrategy":"validation","validationCode":"$raw = Arr::get($data, 'id');\nif (! is_int($raw)) {\n    $raw = is_numeric($raw) ? (int) $raw : 0;\n}\n// or pass a default.","typeGuard":"function isStrictInt(mixed $value): bool { return is_int($value); }","tryCatchPattern":"try {\n    $id = Arr::integer($input, 'id');\n} catch (\\InvalidArgumentException $e) {\n    $id = 0;\n}","preventionTips":["Cast numeric strings to int at the input boundary.","Pass an int default.","Remember Arr::integer is strict (unlike Cache::integer)."],"tags":["collections","array","type-mismatch","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}