space_cadet Posted June 23, 2011 Share Posted June 23, 2011 I have a form that is working except for that I can't get the total amount from the two different arrays i have. $total = $extras + $additional isn't working and honestly, i have a growing feeling that it is not going to be that easy anyway! ... Any suggestions on what formula to use so that I can get a total dollar amount of all of the options that are selected? One more thing...Can anyone with a fresh set of eyes see why the checkbox options are all being produced in a whole new table and not just a new row? I don't know if i can look through any more sets of <tr> and <td> tags! LOL Thanks!!!!! <?php $value = array("Short Trip"=>15.99, "Long Trip"=>28.00, "Overnight"=>10.00); if(isset($_POST['travel'])) { $extras = array("brush"=>1.50, "shampoo"=>1.50, "toothpaste"=>1.50, "cream rinse"=>1.50); if (isset($_POST['extras'])) { foreach ($_POST['extras'] as $additional) { echo "<table border =\"2\"> <tr><td>Item</td><td>Charges</td></tr> <tr><td>".$_POST['travel']."</td> <td> $".$value[$_POST['travel']]."</td></tr> <tr> <td>".$additional."</td> <td> $".$extras[$additional]."</td> </tr> <tr><td>Your total</td> <td>".$total."</td></tr> </table>"; } } } ?> <html> <body> <form action="" method="post"> <table border="2"> <tr> <td colspan="2" align="center" scope="col">Stay Information</td> </tr> <tr> <td><input type="radio" name="travel" value="Short Trip" />Short trip $15.99</td> <td><input type="radio" name="travel" value="Long Trip" />Long trip $28.00</td> </tr> <tr> <td><input type="radio" name="travel" value="Overnight" />Overnight $10.00</td> </tr> </table> <table border="2"> <tr> <td colspan="2" scope="col">What will you need?($1.50 each)</td> </tr> <tr> <td><input type="checkbox" name="extras[]" value="brush" />Brush</td> <td><input type="checkbox" name="extras[]" value="shampoo" />Shampoo</td></tr> <tr> <tr><td><input type="checkbox" name="extras[]" value="toothpaste" />Toothpaste</td> <td><input type="checkbox" name="extras[]" value="cream rinse" />Cream Rinse</td></tr> </tr> <tr><td colspan="2"> <input type="submit" value="Submit"></td></tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/240255-adding-numbers-from-2-different-arrays/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.