将数组的多个值输入到多维数组

时间:2018-05-19 09:54:58

标签: php arrays

我需要帮助制作一个循环,用于将数组内的所有值输入到多维数组

第一个数组是这样的:

$draft = array(
           0 => array( 
               [draft] => "",
               [SKS] =>""
           ),
           N => array( 
               [draft] => "",
               [SKS] =>""
           )

第二个数组是这样的

$csp = array(
    0 => array(//monday
        0 => array(//session 1
             0 => array( //room 405
                    0 => "", //draft 
                    1 => ""  //sks
                ),
                .
                .
                3 => array( //room 408
                    0 => "", //draft 
                    1 => ""  //sks
                )
        )
        .
        5 = array(// session extra
           0 => array( //room 405
                    0 => "", //draft 
                    1 => ""  //sks
                ),
                .
                .
                3 => array( //room 408
                    0 => "", //draft 
                    1 => ""  //sks
                )
        )
    .
    .
    .

    5 => array(//friday
        0 => array(//session 1
             0 => array( //room 405
                    0 => "", //draft 
                    1 => ""  //sks
                ),
                .
                .
                3 => array( //room 408
                    0 => "", //draft 
                    1 => ""  //sks
                )
        )
        .
        5 = array(// session extra
           0 => array( //room 405
                    0 => "", //draft 
                    1 => ""  //sks
                ),
                .
                .
                3 => array( //oom 408
                    0 => "", //draft 
                    1 => ""  //sks
                )
        )

我需要用第二个数组的值填充4维数组,如果它到达$ draft的最后一行然后从第一行重新开始

$csp[0][0][0][0] = $draft[0]['draft'];
$csp[0][0][0][1] = $draft[0]['sks'];
$csp[0][0][1][0] = $draft[1]['draft'];
$csp[0][0][1][1] = $draft[1]['sks'];
$csp[0][0][2][0] = $draft[2]['draft'];
$csp[0][0][2][1] = $draft[2]['sks'];
.
.
$csp[N][N][N][0] = $draft[N]['draft'];
$csp[N][N][N][1] = $draft[N]['sks'];

我已经尝试过使用像这样的循环

    for ($i=0; $i <5 ; $i++) { //hari
    for ($j=0; $j <6 ; $j++) { //sesi
        for ($k=0; $k <4 ; $k++) { //ruang
            for ($l=0; $l <2 ; $l++) { //draft&sks
                for ($m=0; $m <count($draft) ; $m++) { 
                    $csp[$i][$j][$k][$l] = $draft[$m]['draft'];
                    if($l==2){
                    $csp[$i][$j][$k][$l] =$draft[$m]['SKS']; 
                    }
                }                                                        
            }
        }
    }
}

但只有第一个ID和SKS被填入$ csp

如何实现我需要的循环?

0 个答案:

没有答案