如何在php中设置多维数组中的键

如何在php中设置多维数组中的键,php,arrays,Php,Arrays,我对php有疑问,我想设置一个关联数组,我有它的键和值。 我有一个数组$headers和一个多维数组$data,如下所示: $headers=( [0] => Testcase Name [1] => Cell Name [2] => Customer [3] => Flops [4] => Title [5] => Status [6] => Mfix CCR(open/close) [7

我对php有疑问,我想设置一个关联数组,我有它的键和值。 我有一个数组$headers和一个多维数组$data,如下所示:

$headers=(
    [0] => Testcase Name
    [1] => Cell Name
    [2] => Customer
    [3] => Flops
    [4] => Title
    [5] => Status
    [6] => Mfix CCR(open/close)
    [7] => Scenerio-Brief Description
    [8] => Expected Results
    [9] => CCR Status
    [10] => CCR No.
    [11] => Remarks
    [12] => Testcase Path
)

$data=(
    [0] => Array
        (
            [0] => /a/b/c
            [1] =>
            [2] =>
            [3] =>
            [4] =>
            [5] => Done
            [6] => close
            [7] => 2D Elastic with scanformat=parallel
            [8] => No miscompares for both scan and logic tests
            [9] =>
            [10] => 1716280
            [11] =>
            [12] =>
        )

    [1] => Array
        (
            [0] => /x/y/z
            [1] =>
            [2] =>
            [3] =>
            [4] =>
            [5] => Done
            [6] => close
            [7] => 2D Elastic with scanformat=parallel & explicitshifts
            [8] => No miscompares for both scan and logic tests
            [9] =>
            [10] => 1717028
            [11] =>
            [12] =>
        )

    [2] => Array
        (
            [0] => /a/p/q
            [1] =>
            [2] =>
            [3] =>
            [4] =>
            [5] => Done
            [6] =>
            [7] => Error if explicitshifts greater than scan length
            [8] => No miscompares for both scan and logic tests
            [9] =>
            [10] =>
            [11] =>
            [12] =>
        )

    [3] => Array
        (
            [0] => /s/m/p
            [1] =>
            [2] =>
            [3] =>
            [4] =>
            [5] => Done
            [6] =>
            [7] => 2D Elastic + wide 1 Masking with scanformat=parallel
            [8] => No miscompares for both scan and logic tests
            [9] =>
            [10] =>
            [11] =>
            [12] =>
        )

)
我想将数字键[0]..[12]设置为$headers数组的值。 表示我想用$header[0]..$headers[12]替换[0]..[12]

请提供解决方案。

使用:


同意,array_combine是实现这一目标的更干净的方法。竖起大拇指:)
array\u combine
让我很沮丧,数组的大小是一样的,这很挑剔。只是说说而已。问题中的数组大小也是一样的。如果大小不同,那么这是一个完全不同的任务。
$dataWithKeys = [];
foreach ($data as $row) {
    $dataWithKeys[] = array_combine($headers, $row);
}
$result = array();
foreach($data as $key => $val){
    $temp = array(); 
    foreach($val as $k => $v){
       $temp[$header[$k]] = $v; 
    }
    $result[] = $temp;
}