わかりました、まさに私が期待していたものではありません...私は自分のコードがとても読みやすいとは知りませんでした...申し訳ありません! 修正するにはどうすればよいですか? 私は本当に(私が思っていた)合計を得るために単純な数学を達成したいと思っています。私はいたるところを見て、配列に関する非常に多くの情報を読みましたが、明らかに概念を理解していません...これ以上の助けを歓迎し、大いに感謝します!
ラジオ ボタン、チェックボックスがあり、配列を使用して合計購入金額を表示するモック注文フォームを作成しています。私が持っている2つの異なる配列から合計金額を取得できないことを除いて、機能しているフォームがあります。$total = $extras + $additional は機能していません。正直なところ、それほど簡単ではないことを知っておくべきでした。... 選択されたすべてのオプションの合計金額を取得できるように、どの式を使用すればよいかについて何か提案はありますか? また、チェックボックスの項目がまったく新しいテーブルではなく、新しい行にリストされるように、誰かが私を助けることができますか?
前もって感謝します!
さらにいくつかのこと:これをreduxに保持する必要があり、出力をそのままテーブルに保持したいと思います...それ以外は、必要/必要なものを自由に変更してください。
私は PHP 配列を初めて使用し、その値に関してのみ問題を抱えているようですが、PHP で配列がいかに重要であるかを知っているので、それらがどのように機能するかを確認したいと思います!
<?php
/*This stuff is only here because I want to make sure
there are 2 decimal places in the final numbers since
I'm dealing in "money" values*/
$total = number_format ($total,2);
$value = number_format ($value,2);
$additional = number_format ($additional,2);
$value = array("Short Trip"=>15.99, "Long Trip"=>28.99, "Overnight"=>10.99 "Forever"=>99.99);
if(isset($_POST['travel'])) {
$extras = array("Hair Brush"=>1.50, "Shampoo"=>1.50, "Toothpaste"=>1.50,
"Cream Rinse"=>1.50, "Tooth Brush"=>1.50,
"Shower Cap"=>1.50, "Washcloth"=>1.50, "Mouthwash"=>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.99</td>
</tr>
<tr>
<td><input type="radio" name="travel" value="Overnight" />Overnight $10.99</td>
<td><input type="radio" name="travel" value="Forever" />Forever $99.99</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="Hair Brush" />Hair 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><input type="checkbox" name="extras[]" value="Tooth Brush" />Tooth Brush</td>
<td><input type="checkbox" name="extras[]" value="Shower Cap" />Shower Cap</td></tr>
<tr>
<tr><td><input type="checkbox" name="extras[]" value="Washcloth" />Washcloth</td>
<td><input type="checkbox" name="extras[]" value="Mouthwash" />Mouthwash</td></tr>
</tr>
<tr><td colspan="2">
<input type="submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>