Skip to content
Advertisement

Working with an array with periods in key values

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@example.com.

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?

Advertisement

Answer

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'];
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement