Advertisement
Guest User

Untitled

a guest
Apr 24th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. $default = array(
  4.     'a' => array(
  5.         'a' => 'a',
  6.         'b' => 'b',
  7.         'c' => 'c',
  8.     ),
  9. );
  10.  
  11. $user = array(
  12.     'b' => 1,
  13.     'a' => array(
  14.         'b' => 'something',
  15.         'c' => 'something else',
  16.         'd' => 'd',
  17.     ),
  18.     'c' => 2);
  19.  
  20. function fill_in($user, $default) {
  21.     fill_in_aux($user, $default);
  22.     return $default;
  23. }
  24.  
  25. function fill_in_aux($user, &$default) {
  26.     foreach ($user as $key => $value) {
  27.         if (is_array($value)) {
  28.             fill_in_aux($user[$key], $default[$key]);
  29.         } else {
  30.             $default[$key] = $value;
  31.         }
  32.     }
  33. }
  34.  
  35. print_r(fill_in($user, $default));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement