Need help with a regular expression
| From: | Alex Hogan | Date: | Thu, 30 Sep 2004 21:22:02 +0000 |
| Subject: | Need help with a regular expression | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-198348@lists.php.net to get a copy of this message | ||
I have a series of questions that are multiple choice. Some of the
questions have multiple answers to them.
Those questions have answers that are indicated by a checkbox that is
named something like;
Q4_1
Q4_2
etc...
Of those, each one of the checkboxes that indicate a correct answer is
given a point value.
I need only get the total points of question 4 and not the individual
checkbox scores.
What I have;
foreach($_POST as $key => $value){
if($key != 'Submit'){
if($key == ereg("^Q4_.[0-9]$", $key)){
$Q4score[$i] = $value;
}
print $key.": ".$value."<br>";
$Score[$i] = $value;
}
$i++;
}
print 'Q4: '.array_sum($Q4score); - Returns 0
print 'Total: '.array_sum($Score); - Returns correctly
Is my ereg() wrong?
My understanding is ereg("^Q4_.[0-9]$", $key) should look for a $key
starting with 'Q4_' followed by a single number and place those values
into an array named $Q4scores.
What am I missing?
Thanks,
alex hogan