Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php header( "Content-type: text/plain" );
  2.  
  3. $arr1 = array(
  4.     'access' => array(
  5.         'axs_import'        => 'administrator',
  6.         'axs_import_users'  => 'test',
  7.         'axs_goaway'        => '',
  8.     ),
  9.     'database' => array(
  10.         'host' => '12.34.56.78',
  11.         'user' => '',
  12.         'name' => '',
  13.     ),
  14.     'import' => array(
  15.         'key'    => '',
  16.         'search' => '',
  17.     ),
  18. );
  19.  
  20. $arr2 = array(
  21.     'access' => array(
  22.         'axs_import'        => 'administrator',
  23.         'axs_import_users'  => '',
  24.         'axs_settings'      => 'administrator',
  25.         'axs_setings_users' => '',
  26.     ),
  27.     'database' => array(
  28.         'host' => '12.43.21',
  29.         'user' => 'test',
  30.         'pass' => 'new',
  31.         'name' => '',
  32.     ),
  33.     'import' => array(
  34.         'key'    => '',
  35.         'search' => '',
  36.     ),
  37.     'misc' => array(
  38.         'gallery_content' => 500,
  39.     ),
  40. );
  41.  
  42.  
  43. $old = _options( $arr1, _options( $arr1, $arr2 ), 'diff' );
  44. $new = _options( $arr2, $arr1 );
  45. $options = array_merge_recursive( $old, $new );
  46.  
  47. print_r( $options );
  48.  
  49.  
  50.  
  51. function _options( $new, $old, $case = 'compare' )
  52. {
  53.  
  54.     $diff = array();
  55.  
  56.     foreach ( $new as $k => $v)
  57.     {
  58.  
  59.         if ( array_key_exists( $k, $old ) )
  60.         {
  61.             if ( is_array($v) )
  62.             {
  63.                         $rdiff = _options( $v, $old[$k] );
  64.  
  65.                 if ( $case = 'compare' )
  66.                             if ( count($rdiff) ) $diff[$k] = $rdiff;
  67.                 else
  68.                             $diff[$k] = array_intersect( $rdiff, $v );
  69.  
  70.                 unset($rdiff);
  71.  
  72.             }
  73.  
  74.         }
  75.         else
  76.         {
  77.             $diff[$k] = $v;
  78.         }
  79.  
  80.     }
  81.  
  82.     return $diff;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement