【问题标题】:Undefined index - strange?未定义的索引 - 奇怪?
【发布时间】:2012-04-22 18:37:43
【问题描述】:

我遇到了一些奇怪的未定义索引..

$vatcode = 'U25';
echo $this->vatcode_ids['U25']."\n";
echo $this->vatcode_ids[$vatcode]."\n";

foreach($this->vatcode_account_ids as $id => $vatcode){
    echo $vatcode."\n";
    echo $this->vatcode_ids[$vatcode]; // undefined index
}

返回:

681
681
U25  

Notice: Undefined index: U25   in /var/www/.....php on line 64

我不明白?!

【问题讨论】:

  • 也许你的意思是$this->vatcode_ids[$id]
  • 你能发布一个数组的 var_dump 吗?
  • $this->vatcode_account_ids 数组长什么样子?
  • vatcode_account_ids和vatcode_ids有什么关系?
  • 使用trim() 删除开头/结尾不需要的空格

标签: php warnings undefined-index


【解决方案1】:

在通知按摩之前打印的空行中,我假设您的 $vatcode 变量包含一些结束的换行符。如果是这样,它与 $this->vatcode_ids 数组中的任何键都不匹配。

您应该使用丹李在 cmets 中建议的一些修剪功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 2015-02-20
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多