如何将具有相同标签的3个数组中的3个变量连接到php中的第四个数组中
我有 3 个从动态生成的表单中获得的数组(条目数可能可变,但这 3 个数组中每个数组的条目数始终相同):
services[0] => $service1
services[1] => $service2
services[2] => $service3
amount[0] => $amount1
amount[1] => $amount2
amount[2] => $amount3
price[0] => $price1
price[1] => $price2
price[2] => $price3
我如何为其中的每个变量创建一个数组数组? 对于具有相同标签的每个服务,我想创建一个名为服务的数组,如下所示:
Service1[0] => services[0]
Service1[1] => amount[0]
Service1[2] => price[0]
Service2[0] => services[1]
Service2[1] => amount[1]
Service2[2] => price[1]
Service3[0] => services[2]
Service3[1] => amount[2]
Service3[2] => price[2]
并最终创建一个像这样的最终数组:
Services[0] => Service1
Services[1] => Service2
Services[2] => Service3
如果我知道从表单中获得的变量的确切数量,我可以轻松地做到这一点,但因为它是动态生成的我不知道。 谢谢
i have 3 arrays that i get from a dynamically generated form(there could be a variable number of entries but the number of entries for each of these 3 arrays will always be the same):
services[0] => $service1
services[1] => $service2
services[2] => $service3
amount[0] => $amount1
amount[1] => $amount2
amount[2] => $amount3
price[0] => $price1
price[1] => $price2
price[2] => $price3
How do i make an array for each variable of those arrays?
For each service with the same label i want to make an array called service like this:
Service1[0] => services[0]
Service1[1] => amount[0]
Service1[2] => price[0]
Service2[0] => services[1]
Service2[1] => amount[1]
Service2[2] => price[1]
Service3[0] => services[2]
Service3[1] => amount[2]
Service3[2] => price[2]
And eventually make a final array like this:
Services[0] => Service1
Services[1] => Service2
Services[2] => Service3
I could easily do it if i knew the exact number of variables i get from the form but since it's dinamycally generated i don't know that.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 php 中,变量之前需要
$
。In php you need
$
before variables.