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....
looping an array
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: looping an array
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;