本文介绍了多选PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>
<input type="submit" value="Send" />
</form>
<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
if($t=='one')
$price1=12;
if($t=='two')
$price2=2;
$total = $price1 + $price2;
echo $total;
当一个&都选择了两个,我希望结果为14.加法得到14个结果的最佳方法是什么?
When one & two are both selected i'd like the result to be 14. What is the best way to make an addition to obtain 14 as a result ?
推荐答案
必须将if $ t = one等放置在循环内
You must place the if $t = one , etc. inside the loop
这篇关于多选PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!