-2

How can I merge array in multidimensional array . I'm very confuse

I've 2 array

$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"
  }

and I want to check :

if $getName['name'] = $getLate['name'] I want to add totalLate into $getName;

How can I merge them so that the output looks like this

$getLate = [
  0 => {
    "id": 1
    "name": "student1"
    "totalLate": 1
  }
  1 => {
    "id": 3
    "name": "student2"
    "totalLate": 1
  }
  2 => {
    +"id": 4
    +"name": "student3"
    "totalLate": 0
  }
]
Ahmad Karim
  • 459
  • 1
  • 6
  • 17
TryHardz
  • 149
  • 2
  • 11
  • 5
    Possible duplicate of [how to join two multidimensional arrays in php](https://stackoverflow.com/questions/19109815/how-to-join-two-multidimensional-arrays-in-php) – RAUSHAN KUMAR Aug 17 '18 at 11:18

1 Answers1

0
$output = array();
foreach ($getLate as $key => $value){
    $output[] = (object)array_merge((array)$getName[$key], (array)$value);
}
print_r($output);
Siddharth Ramani
  • 661
  • 3
  • 12
  • it's output only 2 array same as $getLate – TryHardz Aug 17 '18 at 11:53
  • 2
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Nic3500 Aug 17 '18 at 12:40