Page 1 of 1

looping an array

Posted: Sun Aug 30, 2009 1:00 pm
by parkerlj
Hi could someone please help me!!! I am making a quote form for someone that will do the quote then and their. You can select several checkboxes, so here's the problem i have collected the boxes they ticked in an array which will be 10,20,40 etc so how do I add all these figures together and append them onto a variable to give a final quote figure. I have been pulling my hair out for days could someone please come to the resue.

Im preying here....

Re: looping an array

Posted: Sun Aug 30, 2009 1:27 pm
by John Cartwright
No need for a loop to calculate the sum, simply use array_sum(), i.e.,

Code: Select all

$sum = 0;
 
if (isset($_POST['your_checkboxes_name'])) {
   $sum = array_sum($_POST['your_checkboxes_name']);
}
 
echo 'Your total is: $'. $sum;