欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

form表單傳遞數(shù)組數(shù)據(jù)、php腳本接收的實(shí)例

 更新時(shí)間:2017年02月09日 09:00:15   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇form表單傳遞數(shù)組數(shù)據(jù)、php腳本接收的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

通過(guò)數(shù)組傳遞表單數(shù)據(jù),可以保存數(shù)據(jù)之間的業(yè)務(wù)屬性關(guān)系,比如有很多Student,每隔Student都有姓名、年齡、性別、愛(ài)好等表單信息。提交表單后還需要針對(duì)每個(gè)student進(jìn)行處理或者保存。這樣肯定需要為每個(gè)student的這些屬性表單建立起關(guān)聯(lián)關(guān)系,一種方式是根據(jù)屬性表單的name上加特殊標(biāo)記進(jìn)行識(shí)別,但是數(shù)組傳遞表單就能使表單數(shù)據(jù)更結(jié)構(gòu)化。

例子如下:

<input type="hidden" name="msginfo[name][]" value="張三"/>
<input type="hidden" name="msginfo[phonenum][]" value="111111111"/>
<input type="hidden" name="msginfo[name][]" value="李四"/>
<input type="hidden" name="msginfo[phonenum][]" value="222222222"/>

php代碼:

<?php 
 $msgInfos = $_POST['msginfo'];
 $phoneNums = $msgInfos['name']; // 為array(-=>張三,1=>李四)
 $phoneNums = $msgInfos['phonenum']; // 為array(0=>111111111,1=>222222222)

例一

<?php
if(isset($_POST['submit'])){
$users = $_POST['user'];
foreach($users as $key=>$val){
  echo 'user ',$key,' = ',$val,'<br />';
}
}
?>
<form method="post">
zhangsan <input type="text" name="user[zhangsan]" value="0" /><br />
lisi <input type="text" name="user[lisi]" value="1" /><br />
wangwu <input type="text" name="user[wangwu]" value="2" /><br />
zhaoliu <input type="text" name="user[zhaoliu]" value="3" /><br />
<input type="submit" name="submit" value="提交" />
</form>

例二

<form method="post">
<?
for($i=0;$i<10;$i++){
?>
<input type="checkbox" name="interests[]" value="<?=$i?>">test<?=$i?><br>
<?
}
?>
<input type="submit">
</form>

<?php
<code class="php keyword">if(isset($_POST)){
 foreach($_POST as $key => $val){
  if(is_array($val)){
    foreach($val as $v2){
    echo "$v2<br>";
    }
  }
 }
}
?>
</code>

以上這篇form表單傳遞數(shù)組數(shù)據(jù)、php腳本接收的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論