How to increment

Instead of having this bloated code how can I increment it please?
Thanks very much

[php]$result = $unit1score + $unit2score + $unit3score + $unit4score + $unit5score + $unit6score + $unit7score + $unit8score + $unit9score + $unit10score + $unit11score + $unit12score + $unit13score + $unit14score + $unit15score + $unit16score + $unit17score + $unit18score + $unit19score + $unit20score + $unit21score + $unit22score + $unit23score + $unit24score + $unit25score + $unit26score + $unit27score + $unit28score + $unit29score + $unit30score + $unit31score + $unit32score + $unit33score + $unit34score + $unit35score + $unit36score + $unit37score + $unit38score + $unit39score + $unit40score + $unit41score + $unit42score + $unit43score + $unit44score + $unit45score + $unit46score + $unit47score + $unit48score + $unit49score + $unit50score + $unit51score + $unit52score + $unit53score + $unit54score + $unit55score + $unit56score + $unit57score + $unit58score + $unit59score + $unit60score + $unit61score ;[/php]

Increment is done by doing $Variable++;

Example:

[php]
$Variable = 0;
Echo “Current is {$Variable}.
”;
While ($Variable < 10) { $Variable++; }
Echo “Variable is now {$Variable}.”;
[/php]

This will return:
Current is 0.
Variable is now 10.

You can simplify your code using the below technique:
[php]
$result=0;
for($i=1;$i<=61;$i++)
{
$test = ‘unit’.$i.‘score’;
$result+=$$test;
}
echo $result;
?>
[/php]

I’m assuming that you have already set the values for the variable from $unit1score …$unit61score

thank you both -
Sajan yes your answer was what I was looking for.
RaythXC yours has really helped with something else!

cheers

Sponsor our Newsletter | Privacy Policy | Terms of Service