如何在多维数组中合并数组。我很困惑
我有2个数组
$getLate = [
0 => {
"id": 1
"name": "student1"
"totalLate": 1
}
1 => {
"id": 3
"name": "student2"
"totalLate": 1
}
]
$getName = [
0 => {
+"id": 1
+"name": "student1"
}
1 => {
+"id": 3
+"name": "student2"
}
2 => {
+"id": 4
+"name": "student3"
}
我想检查一下:
if $getName['name'] = $getLate['name']
我想将totalLate添加到$getName
;
如何合并它们,以使输出看起来像这样
$getLate = [
0 => {
"id": 1
"name": "student1"
"totalLate": 1
}
1 => {
"id": 3
"name": "student2"
"totalLate": 1
}
2 => {
+"id": 4
+"name": "student3"
"totalLate": 0
}
]
答案 0 :(得分:0)
$output = array();
foreach ($getLate as $key => $value){
$output[] = (object)array_merge((array)$getName[$key], (array)$value);
}
print_r($output);