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


How to join 3 variables from 3 arrays with the same labels into a fourth array in 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

如果我知道从表单中获得的变量的确切数量,我可以很容易地做到这一点,但由于它是二霉菌生成的,我不知道。谢谢

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

在 php 中,您需要在变量之前$