我正在尝试使用 foreach 循环总结复选框值的值......但我对在哪里添加符号感到困惑,以便这些值可以相加。
我在哪里包括加号,以便它可以总结任何数值,以便我可以得到总数?
<?php
if(isset($_POST["submit"])){
$main_odds = $_POST["total_odds"];
if(!empty($main_odds)){
echo "You have selected the following games ";
foreach ($main_odds as $final_odd){
echo "<td>$final_odd</td>" ;
}
}else{
echo "You have not selected any odds";
}
}
$total_odds = "";
?>
<table>
<thead>
<tr>
<th>calculate</th>
<th>odds</th>
</tr>
</thead>
<tbody>
<?php foreach($games as $game): ?>
<tr>
<td><?= $game->odds; ?></td>
<td>
<form method="Post" action="">
<input type="checkbox" name="total_odds[]" value="<?= $game->odds; ?>">
</td>
</tr>
<?php endforeach; ?>
<input type="submit" name="submit"/>
</form>
</tbody>
</table>
ibeautiful
子衿沉夜