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 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝