$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...
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 ){