我有两个具有以下结构的数组
array
'main' => array
'firstYearStudents' => array
0 => '10'
1 => '12'
'secondYearStudents' => array
0 => '8'
1 => '9'
'total' => array
'totalFirstYear' => '22'
'totalSecondYear' => '17'
但我想得到以下一个
array
'main' => array
'firstYearStudents' => array
0 => '10'
1 => '12'
2 => '22'
'secondYearStudents' => array
0 => '8'
1 => '9'
2 => '17'
但我不明白如何将“总”数组中的值附加到“主”数组中的值。你能告诉我应该朝哪个方向移动吗?
编辑:如果我有以下键以及上述键怎么办?
array
'main' => array
'firstYearStudents' => array
0 => '10'
1 => '12'
'secondYearStudents' => array
0 => '8'
1 => '9'
'programCode' => array
0 => '03.02.01'
1 => '03.01.01'
'total' => array
'totalFirstYear' => '22'
'totalSecondYear' => '17'
'programCode' => '-'
那么所需的结构应该是这个样子
array
'main' => array
'firstYearStudents' => array
0 => '10'
1 => '12'
2 => '22'
'secondYearStudents' => array
0 => '8'
1 => '9'
2 => '17'
'programCode' => array
0 => '03.02.01'
1 => '03.01.01'
2 => '-'
我尝试了以下方法,但我得到了命名的密钥,所以我无法访问这些密钥。
$i = 0;
foreach ($studentsEditInfo['main'] as $values) {
$studentsEditInfo['main'] = array_merge($values, $studentsEditInfo['total'][$i]);
$i++;
}
沧海一幻觉
回首忆惘然