arrays - PHP function like array_replace() but does not add unknown keys -


i have associative array holds settings of object. have function allows user override these setting passing associative array of replacement settings. can use array_replace() don't want values unknown associative array keys added settings.

e.g.

$settings = array(     'colour' => 'red',     'size' => 'big' );  $settings = array_replace( $settings, array(     'size' => 'small',     'weight' => 'heavy'    ) ); 

i want settings produce:

array (     [colour] => red     [size] => small ) 

instead this:

array (     [colour] => red     [size] => small     [weight] => heavy ) 

first need filter out unwanted items array_intersect_key.

$settings = array(     'colour' => 'red',     'size' => 'big' );  $new_settings = array(     'size' => 'small',     'weight' => 'heavy'    );  $settings = array_merge($settings, array_intersect_key($new_settings, $settings)); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -