首页 > 解决方案 > 如何在PHP中获取具有html同名类的数组

问题描述

我是 PHP 新手,找不到我需要的东西。所以我的问题是我在 HTML 中有 4 个同名输入,我想在 PHP 中用它们创建一个数组。有没有办法做到这一点?查看下面的图片:4 个输入的照片

所以这 4 个输入具有相同的名称,我想获取用户输入的信息并将其插入 HTML 页面,请回答我的问题或推荐更好的方法!

这是我的代码:

   <input class="inputText" type = "text" class="form-control" placeholder="Some text here"/>
   <input class="inputText" type = "text" class="form-control" placeholder="Some text here"/>
   <input class="inputText" type = "text" class="form-control" placeholder="Some text here"/>
   <input class="inputText" type = "text" class="form-control" placeholder="Some text here"/>

标签: phphtml

解决方案


用这个 :

 <input class="inputText" type = "text" class="form-control" name="text[]" placeholder="Some text here" />
       <input class="inputText" type = "text" class="form-control"  name="text[]"  placeholder="Some text here"/>
       <input class="inputText" type = "text" class="form-control" name="text[]"  placeholder="Some text here"/>
       <input class="inputText" type = "text" class="form-control"  name="text[]"  placeholder="Some text here"/>

那么当您打印 $_POST 时,您将在 php 文件中获得“名称”数组


推荐阅读