当前位置:Gxlcms > PHP教程 > php获取从html表单传递数组的方法

php获取从html表单传递数组的方法

时间:2021-07-01 10:21:17 帮助过:3人阅读

本文实例讲述了php获取从html表单传递数组的方法。分享给大家供大家参考。具体如下:

将表单的各个元素的name都设置成同一个数组对象既可以以数组的方式传递表单值

html页面如下:

  1. <form method="post" action="arrayformdata.php">
  2. <label>Tags</label>
  3. <input type="text" name="tags[]"/>
  4. <input type="text" name="tags[]"/>
  5. <input type="text" name="tags[]"/>
  6. <input type="text" name="tags[]"/>
  7. <input type="text" name="tags[]"/>
  8. <input type="submit" value="submit">
  9. </form>
  10. </html>

arrayformdata.php页面如下:

  1. <?php
  2. $postedtags = $_POST['tags'];
  3. foreach ($postedtags as $tag){
  4. echo "<br />$tag";
  5. }
  6. ?>

希望本文所述对大家的php程序设计有所帮助。

人气教程排行