{"record":{"id":"657df64d9acab55b","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-a-float-s-found","errorCode":null,"errorMessage":"Array value for key [%s] must be a float, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be a float, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":401,"sourceCode":"                    $result[] = $value;\n                }\n            }\n        }\n\n        return $result;\n    }\n\n    /**\n     * Get a float item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function float(ArrayAccess|array $array, string|int|null $key, ?float $default = null): float\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_float($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Array value for key [%s] must be a float, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Remove one or many array items from a given array using \"dot\" notation.\n     *\n     * @param  array  $array\n     * @param  array|string|int|float  $keys\n     * @return void\n     */\n    public static function forget(&$array, $keys)\n    {\n        $original = &$array;\n","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Arr.php#L383-L419","documentation":"Thrown by Arr::float() when the resolved value is not a PHP float. Note is_float() is strict: an int 5 is not a float and will throw, unlike filter_var-based paths.","triggerScenarios":"Calling Arr::float($data, 'key') where the value is an int, non-numeric string, bool, array, or null.","commonSituations":"JSON config where a rate is encoded as an integer; cache/API payloads with mixed numeric types; missing keys.","solutions":["Pass a float default: Arr::float($data, 'key', 0.0).","Cast the source to float before lookup: (float) $data['rate'].","Use Arr::get() and cast manually when int values are valid."],"exampleFix":"// before\n$rate = Arr::float($config, 'rate'); // int 5 throws\n// after\n$rate = Arr::float($config, 'rate', 0.0);","handlingStrategy":"validation","validationCode":"$raw = Arr::get($data, 'rate');\nif (! is_float($raw)) {\n    $raw = (float) $raw; // explicit cast if numeric\n}\n// or guard before calling Arr::float().","typeGuard":"function isStrictFloat(mixed $value): bool { return is_float($value); }","tryCatchPattern":"try {\n    $rate = Arr::float($config, 'rate');\n} catch (\\InvalidArgumentException $e) {\n    $rate = 0.0;\n}","preventionTips":["Cast numeric sources to float before lookup.","Pass a float default.","Remember ints are not floats under is_float()."],"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"}