Re: Need help with a regular expression

From: Date: Thu, 30 Sep 2004 22:48:17 +0000
Subject: Re: Need help with a regular expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198359@lists.php.net to get a copy of this message
Please ignor... I got it... alex On Thu, 30 Sep 2004 16:22:02 -0500, Alex Hogan <hogana@gmail.com> wrote: > 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 >

« previous php.general (#198359) next »