如何将具有相同标签的3个数组中的3个变量连接到php中的第四个数组中

发布于 2024-12-21 05:38:37 字数 852 浏览 1 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

源来凯始玺欢你 2024-12-28 05:38:37
for($i=0;$i<3;$i++){
  $Services[$i]=array($services[$i],$amount[$i],$price[$i]);
}

在 php 中,变量之前需要 $

for($i=0;$i<3;$i++){
  $Services[$i]=array($services[$i],$amount[$i],$price[$i]);
}

In php you need $ before variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文