PHP多维数组到单个数组

I have a form that allows multiple values for inputs

Car One

<input type="text" name="vehicle[]" placeholder="Enter Your Vehicle" />

Car Two

<input type="text" name="vehicle[]" placeholder="Enter Your Vehicle" />

When submitted it translates to an array like so

["vehicle"]=>
  array(1) {
    [0]=>
    string(5) "Acura"
    [1]=>
    string(5) "Mazda"
 }

["doors"]=>
  array(1) {
    [0]=>
    string(6) "4 Door"
    [1]=>
    string(6) "2 Door"
  }

I want to then translate this to individual arrays that are like so

[VehicleOne]=>
  array(1) {
    [vehicle]=>
    string(5) "Acura"
    [doors]=>
    string(5) "4 door"
  }

I have a custom function I created that does this but I am wondering if there are native php methods that can be used instead of multiple loops?

So this is what I am currently using. Not every $_POST value is an array so I have to check and if is then I divide them up.

foreach ($fields as $key => $row) {

   if(is_array($row)){

     foreach ($row as $column => $value) {

        $doctors[$column][$key] = $value;

     }

  }

}

No need, just construct the array the way you want it in the inputs:

<input type="text" name="data[0][vehicle]" placeholder="Enter Your Vehicle" />
<input type="text" name="data[1][vehicle]" placeholder="Enter Your Vehicle" />
<input type="text" name="data[0][doors]"   placeholder="Enter Your Doors" />
<input type="text" name="data[1][doors]"   placeholder="Enter Your Doors" />

Then $_POST will contain:

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [vehicle] => Acura
                    [doors] => 4 door
                )

            [1] => Array
                (
                    [vehicle] => Maza
                    [doors] => 2 door
                )
        )
)

If you can't/won't change the form, then something like:

foreach($_POST['vehicle'] as $k => $v) {
    $result[] = ['vehicle' => $v, 'doors' => $_POST['doors'][$k]];
}

Will yield:

Array
(
    [0] => Array
        (
            [vehicle] => Acura
            [doors] => 4 door
        )

    [1] => Array
        (
            [vehicle] => Maza
            [doors] => 2 door
        )
)

Using something like VehicleOne etc. is pointless when using arrays as you are only doing this to make it unique, when 0, 1, etc. already is.

Maybe this can work for you?
I create a temporary array with associative keys that I later extract to multiple arrays ($vehicle1 and 2).

Foreach($vehicle["vehicle"] as $key => $v){
    $temp["vehicle" . ($key+1)]["vehicle"] = $v;
    $temp["vehicle" . ($key+1)]["doors"] = $d["doors"][$key];
}
Extract($temp);
Var_dump($vehicle1, $vehicle2);

It's one loop, not multiple loops at least.

https://3v4l.org/ltoEs