【发布时间】:2013-07-16 23:55:19
【问题描述】:
我在 php 中有一个数组数组。两个数组都没有索引(它们使用键)。
$this->confArr["$sectionName"] = Array(); // case 1
这返回真:
isset($this->confArr["$sectionName"]);
因为已经设置了一个名为 $sectionName 的元素。
$this->confArr["$sectionName"]["$itemKey"] = $itemValue; //case 2
我不知道为什么,但这总是返回 FALSE
array_key_exists($itemKey, $this->confArr["$sectionName"]);
有什么问题?
【问题讨论】:
-
$sectionName和$itemKey真的设置了吗? -
如果
$itemValue是null(或者如果你没有给它一个值)那么isset将返回false。是吗? -
打印 confArr["$sectionName"]["$itemKey"];在判断之前
-
isset()检查该值是否已设置且不为空。$itemValue返回什么 -
@ClaudioFerraro:很可能您至少在这些断言中的一个中是错误的。如果一切都是这样,你会得到
true。虽然isset可能存在错误并且您是第一个发现它的人,但这种可能性极小。
标签: php