Updating or adding data to an associative array as a cache I have this if else statement where I don't know how to remove the code duplication

if(array_key_exists($key,$cachetable))
{
 if($cachetable[$key] != $newdata[$key])
  {
    //data existed but is not valid
    //update the cachetable
    $cachetable[$key] == $newdata[$key]
  }
}

else
{
    //data didn't existed before in cache so add it now
    //update the cachetable
    $cachetable[$key] == $newdata[$key]
 }
Modify the code to this:

//just use the AND operator (&amp;&amp;) to check if it's both existing AND valid
//use strict comparison (===) whenever possible
if(array_key_exists($key,$cachetable) &amp;&amp; $cachetable[$key] === $newdata[$key]){
    //data exists and valid
} else {
    //data doesn't exist or isn't valid
    //to assign data, use a single equal (=). 
    //A double equal (==) is a loose comparison
    $cachetable[$key] = $newdata[$key];
 }




//this one checks if it's not in the array
//or if it does, it checks if it's not valid
//when either one is true, the condition passes
if(!array_key_exists($key,$cachetable) || $cachetable[$key] !== $newdata[$key]){
    //data doesn't exists or isn't valid
}