dongqiao0953 2015-08-03 13:38
浏览 37
已采纳

未定义的偏移量:php数组中的0

if ( count( $entry_array>0 ) )  
{
    $GLOBALS[ 'year' ] = substr($entry_array[0], 5, 2);     //line 22 
    $GLOBALS[ 'month' ] = substr($entry_array[0], 7, 2);    //line 23     
    $GLOBALS[ 'day' ] = substr($entry_array[0], 9, 2);      //line 24     
}

error at line 22, 23, 24 saying Notice: Undefined offset: 0

Any idea to solve this issue..

  • 写回答

4条回答 默认 最新

  • dongliang9682 2015-08-03 13:40
    关注

    The if should read

    if (count($entry_array) > 0)
    

    In your code, you are evaluating $entry_array > 0, which would return a boolean. Then you are getting the count of that value, which always usually results in 1 if the argument is not an array.

    When evaluating 1 as bool (for the if), it evaluates to true, so eventually you execute the body of the if even if the array is empty.

    So then it is not guaranteed to work, since maybe your array doesn't have index 0, but likely this was the cause, so I'd try this first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据