這篇文章主要介紹了php獲取從html表單傳遞數組的方法,實例分析了php操作表單元素的技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了php獲取從html表單傳遞數組的方法。分享給大家供大家參考。具體如下:
將表單的各個元素的name都設置成同一個數組對象既可以以數組的方式傳遞表單值
html頁面如下:
- <form method="post" action="arrayformdata.php">
- <label>Tags</label>
- <input type="text" name="tags[]"/>
- <input type="text" name="tags[]"/>
- <input type="text" name="tags[]"/>
- <input type="text" name="tags[]"/>
- <input type="text" name="tags[]"/>
- <input type="submit" value="submit">
- </form>
- </html>
arrayformdata.php頁面如下:
- <?php
- $postedtags = $_POST['tags'];
- foreach ($postedtags as $tag){
- echo "<br />$tag";
- }
- ?>
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答