Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.33 KB | None | 0 0
  1. <?php
  2. $ar1 = ['a' => ['b' => 'c', 'd' => 'e']];
  3. $ar2 = ['a' => ['d' => 'f']];
  4.  
  5. function merge($from, $to)
  6. {
  7.     $result = $to;
  8.    
  9.     foreach ($from as $itemKey => $item) {
  10.         foreach($item as $k => $v) {
  11.             $result[$itemKey][$k] = $v;
  12.         }
  13.     }
  14.    
  15.     return $result;
  16. }
  17.  
  18.  
  19. echo merge($ar2, $ar1) === ['a' => ['b' => 'c', 'd' => 'f']];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement