Store Float As Index¶
With PHP, floats cannot be used directly as array indexes because array keys must be either integers or strings. If you attempt to use a float as an index, PHP will automatically cast it to an integer, potentially causing unexpected behavior. However, you can explicitly cast the float to a string to preserve its precision as an index. Later, due to PHP’s type juggling, you can still perform arithmetic with it seamlessly.
See Also¶
Storing float as keys [Try me]