php - Update array but don't add new items -


so have 2 arrays. old , new one. want update new array variables old array don't want add new indexes in old array aren't in new array.

$old_array = array("1" => "one", "2" => "two", "3" => "three", "4" => "four"); $new_array = array("1" => "1", "2" => "2", "3" => "3"); 

so want new array be:

$updated_array = array("1" => "one", "2" => "two", "3" => "three"); 

could me effective way this?

can try using foreach(). example:

$old_array = array("1" => "one", "2" => "two", "3" => "three", "4" => "four"); $new_array = array("1" => "1", "2" => "2", "3" => "3"); $updated_array = array(); foreach($new_array $key=>$val){     if(isset($old_array[$key])){         $updated_array[$key] = $old_array[$key];     } }  print '<pre>'; print_r($updated_array); print '</pre>'; 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -