I'm getting data from an array. For some reason the array has key values like [3.3]
which I'm having trouble retrieving data from.
I have this array [3.3] => First Name [3.6] => Last Name[2] => [email protected]
.
When I try to call $array[3.3]
it returns null, but when I call $array[2]
I am given the e-mail. Any ideas?
Arrays can only have integers and strings as keys. You can simulate arrays and use objects as keys with SplObjectStorage .
The array_keys() function is used to get all the keys or a subset of the keys of an array. Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned.
This is not possible - array keys must be strings or integers.
From php manual :
Floats in key are truncated to integer.
So you're trying to get $array[3] which does not exist, so you get Null
Use single quotes when referencing the key value (basically treat it like a string, that's what PHP is probably doing)
echo $array['3.3'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With