RE: [PHP] Branching blunder
| From: | Jay Blanchard | Date: | Thu, 05 Aug 2004 14:15:17 +0000 |
| Subject: | RE: [PHP] Branching blunder | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-192864@lists.php.net to get a copy of this message | ||
[snip]
if($ans_three[$qzid] === 'None of the above' || $ans_three[$qzid] ===
'All of the above'){
if($ans_four[$qzid] === 'None of the above' || $ans_four[$qzid] ===
'All of the above'){
$answers = rand(6,8);
}
$answers = 5;
}
else{
$answers = rand(1,4);
}
However when I run it, it checks everything correctly until it has
answer three and four having 'All of the above' and 'None of the above',
then it branches to $answer = 5, only. Why?
[/snip]
Because $answers = 5; is the last check of $answers unless the else
statement is invoked. Try this...
if($ans_three[$qzid] === 'None of the above' || $ans_three[$qzid] ===
'All of the above'){
if($ans_four[$qzid] === 'None of the above' || $ans_four[$qzid] ===
'All of the above'){
$answers = rand(6,8);
} elseif($ans_four[$qzid] !== 'None of the above' || $ans_four[$qzid]
!== 'All of the above'){
$answers= 5;
}
}
else{
$answers = rand(1,4);
}