我正在尝试以键-值格式合并数组,但是不幸的是,我无法获得所需的结果。通过打印以下数组,我得到以下结果。
$material = array_merge($dataArrMaterial,$dataTotalMaterialQty);
_print($material);
Array(
[0] => Array
(
[material_name] => 1041
[material_qty] => 30
)
[1] => Array
(
[material_name] => 1046
[material_qty] => 10
)
[3] => Array
(
[material_qty_req] => 90
)
[4] => Array
(
[material_qty_req] => 30
)
)
但是我想要这样的结果
Array(
[0] => Array
(
[material_name] => 1041
[material_qty] => 30
[material_qty_req] => 90
)
[1] => Array
(
[material_name] => 1046
[material_qty] => 10
[material_qty_req] => 30
)
预先感谢
答案 0 :(得分:1)
您可以使用php的$result= [];
foreach($dataArrMaterial as $key => $value){
$result[$key] = array_merge($dataArrMaterial[$key], $dataTotalMaterialQty[$key]);
}
print_r($result);
方法。
foreach()
答案 1 :(得分:0)
您必须循环第一个数组,然后使用array_merge合并多维数组。
extension MySchedulerViewController: ScheduleViewControllerDelegate{
func mySchedule(imgIcon: [String], proName: [String], proTime: [String]) {
programImgUrlArray = imgIcon
programNameArray = proName
programTimeArray = proTime
print("Hello ")
DispatchQueue.main.async {
self.scheduleTableView.reloadData()
}
}
}