php - 如何在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"/>
解决方案
用这个 :
<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 文件中获得“名称”数组
推荐阅读
- javascript - 如何在图表js的Y轴上应用美元符号?
- angular - 在项目中使用 ng6-toastr 后,请在规范文件 jasmine 中使用 setRootViewContainerRef 设置根 ViewContainerRef
- javascript - 专注于模糊上新创建的输入字段
- javascript - 事件监听器没有触发?
- c++ - 无法使用 soci 库连接到 SQL Server
- c# - 检测无 BOM 或有 BOM 的 utf-8
- javascript - 避免在ajax中等待其他进程完成
- json - 如果对象的所有字段都为空,如何将对象设置为空?
- python - 如何在 Google Colab 中安装 CUDA - 没有 ATen_cuda 库无法初始化 CUDA
- java - 如何在 Java 的整个代码中使用一个变量的值?