牛骨文教育服务平台(让学习变的简单)
博文笔记

用PHP表单传递数组

创建时间:2014-05-08 投稿人: 浏览次数:128

                                                                         用PHP表单传递数组

test.php

formmethod="post" action="test2.php">
<input name="a[]" value="1" />
<input name="a[]" value="2" />
<input name="a[]" value="3" />
<input type="submit"  value="提交"/>
</form>

test2.php

<?php

print_r($_POST["a"]);
?>

结果:

Array( [0] => 1 [1] => 2 [2]=> 3 )

 

 

test.php

formmethod="post" action="test2.php">
<input name="a[4]" value="1" />
<input name="a[5]" value="2" />
<input name="a[6]" value="3" />
<input type="submit"  value="提交"/>
</form>

 

test2.php

<?php

print_r($_POST["a"]);
?>

结果:

Array( [4] => 1 [5] => 2 [6]=> 3 )

 

test.php

formmethod="post" action="test2.php">
<input name="a[11]" value="1"/>
<input name="a[22]" value="2"/>
<input name="a[33]" value="3"/>
<input type="submit"  value="提交"/>
</form>

 

test2.php

<?php

print_r($_POST["a"]);
?>

结果:

Array( [11] => 1 [22] => 2 [33]=> 3 )

 

一个动态生成的PHP表单数组,不依靠Javascript,就可以将很多数据仅仅以一个数组变量的方式提交上去
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。