dtqi87613 2014-02-16 08:55
浏览 84
已采纳

注意:未定义的偏移量:0 ... 25

$score = 0;
$topics = array();
for ($i = 0; $i < count($user_responses); $i++) {
    if ( ((int)$user_responses[$i]['response'])+((int)$mismatch_responses[$i]['response']) == 3 ){
        $score += 1;
        array_push($topics, $user_responses[$i]['topic_name']);
    }
}

It's appear

Notice: Undefined offset: 0

Notice: Undefined offset: 1

Notice: Undefined offset: 2

....

Notice: Undefined offset: 25

can anybody help me?

Thanks...

  • 写回答

1条回答 默认 最新

  • doujiaoben28596 2014-02-16 09:00
    关注

    You can do two things in this case. Change the error reporting to 'E_ALL & ~E_NOTICE' so you won't be bothered with this messages. Or use the 'isset' function to check if a variable exists.

    I think you problem lays here:

    if ( ((int)$user_responses[$i]['response'])+((int)$mismatch_responses[$i]['response']) == 3 ){
    

    you should first check if both variables exists, and use it if they do:

    if (!isset($user_responses[$i]['response']) || !isset($mismatch_responses[$i]['response'])) continue; //skips the loop if one of the variables does not exist
    
    if ( ((int)$user_responses[$i]['response'])+((int)$mismatch_responses[$i]['response']) == 3 ){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单纯型python实现编译报错
  • ¥15 c++2013读写oracle
  • ¥15 c++ gmssl sm2验签demo
  • ¥15 关于模的完全剩余系(关键词-数学方法)
  • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音