是一個新手,我有一個複選框,將值傳遞給一個foreach循環,然後給我所選項目的結果作爲一個列表工作正常。但是,我想獲得以獲得所有的個人可能每個單獨可能每個新變量下,以便我可以分開重新使用所有選中的值。請幫助顯示單個值的foreach與從複選框的值
表格。
<form action="" method="post"
<a target="_blank" href="paris.jpg"><img src="flour.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg flour-50ksh"/><input type="checkbox" name="shipping[]" value="$50.00"><label>50 kg flour-50ksh</label>
<a target="_blank" href="paris.jpg"><img src="milk.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg milk-50ksh"/><input type="checkbox" name="shipping[]" value="$10.00 "><label>50 kg milk-10ksh</label>
<a target="_blank" href="paris.jpg"><img src="maize.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg maize-50ksh"/><input type="checkbox" name="shipping[]" value="$20.00 "><label>50 kg maize-20ksh</label>
<a target="_blank" href="paris.jpg"><img src="oil.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg oil-50ksh"/><input type="checkbox" name="shipping[]" value="$30.00 "><label>50 kg oil-30ksh</label>
<a target="_blank" href="paris.jpg"><img src="rice.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg rice-50ksh"/><input type="checkbox" name="shipping[]" value="$40.00 "><label>50 kg rice-40ksh</label><br/>
<a target="_blank" href="paris.jpg"><img src="soap.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg soap-50ksh"/><input type="checkbox" name="shipping[]" value="$50.00"><label>50 kg soap-50ksh</label>
<a target="_blank" href="paris.jpg"><img src="juice.jpg" alt="Paris" style="width:150px"></a><input type="checkbox" name="day[]" value="50 kg juice-50ksh"/><input type="checkbox" name="shipping[]" value="$50.00"><label>50 kg juice-50ksh</label><br>
<label for="name"> Mobile:</label>
<input type="number" placeholder="10" id="mobile" name="mobile" maxlength="10" size="10" pattern="[0-10]{10}" required/>
<label for="name">Names:</label>
<input type="text" id="name" name="name" required formtarget="_blank"/>
<label for="location">location details:</label>
<input type="text" id="location" name="location" required/>
<input type="hidden" name="submitted" value="true"/><br>
<input type="submit" name="submit" value="Submit"/><br>
窗體有複選框,忽略其他。
PHP代碼
<?php
if(isset($_POST['submit'])){
foreach($_POST['day'] as $day)
{
echo $day;
}
}
?>
我得到什麼 50千克奶50ksh50公斤玉米50ksh50公斤油50ksh50公斤大米,50ksh50公斤果汁50ksh
我怎麼可以把它像一個== 50公斤牛奶ksh50 b = .... c = ...這樣我可以分配也許$約翰=一個?那麼我將能夠重用$約翰?
請幫忙。
我不能明白你的要求,因爲它沒有意義的冗餘變量聲明爲全局範圍。簡而言之,請描述你想要完成這項任務。 – mickmackusa
我只想獲取所有從複選框中選中的值。您有任何建議嗎? –