Reputation: 45
following foreach loop run inside another foreach loop
foreach(array_combine($hotels, $charges) as $hotel => $charge){
echo "<input type='radio' name='$location' value='$charge'> $hotel - <b>Rs.$charge.00</b><br>";
}
$charge is some integer value, I want to get the sum value of this radio button selections. How can I do this?
Upvotes: 0
Views: 491
Reputation: 5484
Don't know if you wanted only selected checkboxes sum or all. If all, then this will work.
Create new variable and add $charge
to it on every iteration.
$chargeSum = 0;
foreach(array_combine($hotels, $charges) as $hotel => $charge){
echo "<input type='radio' name='$location' value='$charge'> $hotel - <b>Rs.$charge.00</b><br>";
$chargeSum += $charge;
}
echo 'Sum: '.$chargeSum;
Otherwise you have to use jQuery, this question has couple of answers for this.
Upvotes: 1