如何在 PHP 中循环访问一系列具有特定前缀的响应变量?
我正在将表单发布到 php 脚本。该表单包含动态数量的名为cardObjectX 的字段,其中X 是一个计数器。示例:cardObject1、cardObject2 等。我需要循环遍历我的 php 脚本中的所有 cardObject 字段,但因为我们不知道任何给定的帖子会有多少个,所以我们无法对字段名称进行硬编码。
有没有办法可以获取以 cardObject 开头的所有字段的数组?
I'm posting a form to a php script. The form contains a dynamic number of fields named cardObjectX, where X is a counter. Example: cardObject1, cardObject2, and so on. I need to loop through all the cardObject fields in my php script, but because we don't know how many there will be for any given post, we can't hard-code the field names.
Is there a way I can grab an array of all the fields that start with cardObject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以帮助您开始:
this should help you get started:
在输入中使用这种命名风格可以像这样在 php 中以数组形式访问这些输入:
或者像这样循环访问每个 cardObject:
using this naming style in your inputs makes it possible to access these inputs as an array in php like this:
or loop throug every cardObject like this: