【问题标题】:Note: Undefined Offset: 2 [duplicate]注意:未定义的偏移量:2 [重复]
【发布时间】:2019-02-06 08:30:30
【问题描述】:

我为这个例外找到的答案不是很有帮助。谁能告诉我这里出了什么问题?

谢谢

    for ($x = 0; $x <= $cartcount; $x++)
    {
      $innerarray = $cart[$x];              //this is the exception-producing line
      $quantity = $innerarray['quantity'];
      $title = $innerarray['articleTitle'];
      $articlenumber = $innerarray['articleNumber'];

      $outputQNT[] = $innerarray['quantity'];

      $outputTITLE[] = $innerarray['articleTitle'];

      $outputATNBR[] = $innerarray['articleNumber'];
    }

【问题讨论】:

    标签: php exception undefined offset


    【解决方案1】:

    数组从零开始,以总数组长度为 1 结束。 所以在for循环中:

    for ($x = 0; $x <$cartcount; $x++){}
    

    如果 $cartcount = 2 则数组索引为 [0,1]

    如果还有问题,请使用:

    array_values($cartcount)
    

    它将返回具有正确索引的数组

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2012-02-08
      相关资源
      最近更新 更多