本文介绍了使用键值中有句点的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从数组中获取数据.出于某种原因,该数组具有诸如 [3.3]
之类的键值,我无法从中检索数据.
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.
我有这个数组 [3.3] =>名字 [3.6] =>姓氏[2] =>email@example.com
.
当我尝试调用 $array[3.3]
时,它返回 null,但是当我调用 $array[2]
时,我收到了电子邮件.有什么想法吗?
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?
推荐答案
在引用键值时使用单引号(基本上把它当作一个字符串,这可能是 PHP 正在做的)
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'];
这篇关于使用键值中有句点的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!