title: Get the key and value difference between to similar objects in PHP
body: <p>I have two similar objects: 
  Object old: </p>
  
  <pre><code>object(Party)#203 (16) {
    ["connection":protected]=&gt;
    object(Connection)#202 (6) {
      ["token":"Connection":private]=&gt;
      string(64) "xyzxxyzxyz"
      ["url":"Connection":private]=&gt;
      string(33) "https://api.test.com"
      ["singularAction"]=&gt;
      string(5) "party"
      ["pluralAction"]=&gt;
      string(7) "parties"
      ["action"]=&gt;
      string(5) "party"
    }
    ["emailAddresses"]=&gt;
    array(3) {
      [0]=&gt;
      array(3) {
        ["id"]=&gt;
        int(273530863)
        ["type"]=&gt;
        NULL
        ["address"]=&gt;
        string(19) "test@gmail.com"
      }
      [1]=&gt;
      array(3) {
        ["id"]=&gt;
        int(274183291)
        ["type"]=&gt;
        NULL
        ["address"]=&gt;
        string(18) "testMail1@test.com"
      }
      [2]=&gt;
      array(3) {
        ["id"]=&gt;
        int(278650133)
        ["type"]=&gt;
        NULL
        ["address"]=&gt;
        string(26) "emailUpdate@test.co.uk"
      }
    }
  }
  </code></pre>
  
  <p>And object updated:</p>
  
  <pre><code>object(Party)#201 (16) {
    ["connection":protected]=&gt;
    object(Connection)#202 (6) {
      ["token":"Connection":private]=&gt;
      string(64) "xyzxxyzxyz"
      ["url":"Connection":private]=&gt;
      string(33) "https://api.test.com"
      ["singularAction"]=&gt;
      string(5) "party"
      ["pluralAction"]=&gt;
      string(7) "parties"
      ["action"]=&gt;
      string(5) "party"
    }
    ["emailAddresses"]=&gt;
    array(4) {
      [0]=&gt;
      array(3) {
        ["id"]=&gt;
        int(273530863)
        ["type"]=&gt;
        NULL
        ["address"]=&gt;
        string(19) "test@gmail.com"
      }
      [1]=&gt;
      array(3) {
        ["id"]=&gt;
        int(274183291)
        ["type"]=&gt;
        NULL
        ["address"]=&gt;
        string(18) "testMail1@test.com"
      }
      [2]=&gt;
      array(3) {
        ["id"]=&gt;
        int(278650133)
        ["type"]=&gt;
        NULL
        ["address"]=&gt;
        string(26) "emailUpdate@test.co.uk"
      }
      [3]=&gt;
      array(1) {
        ["address"]=&gt;
        string(27) "testMailtest12345@gmail.com"
      }
    }
  }
  </code></pre>
  
  <p>Visually the difference is the last email address appearing as the last entry in the updated object. How can I highlight that difference in PHP and grab it?
  I would like to check every entry of both objects, spot the differences in terms of key and value and do something with it.</p>
  
  <p>What I've managed to write is this: </p>
  
  <pre><code>//Get the updated object....  
          $newObject = $this;
          //Now get the object before update was executed...
          $oldObj = $this-&gt;oldObject;
  
          //Remove object memebers from the new object for easy comparison with the old...
          unset($newObject-&gt;oldObject, $newObject-&gt;about, $newObject-&gt;createdAt, $newObject-&gt;updatedAt, $newObject-&gt;lastContactedAt, $newObject-&gt;pictureURL);
          //Remove object memebers from the old object....
          unset($oldObj-&gt;about, $oldObj-&gt;createdAt, $oldObj-&gt;updatedAt, $oldObj-&gt;lastContactedAt, $oldObj-&gt;pictureURL);
  
          $varsNewObj = get_object_vars($newObject);
          $varsOldObj = get_object_vars($oldObj);
          //Remove further unneeded memebers....
          unset($varsNewObj['connection']);
          unset($varsOldObj['connection']);
  
          $arrayData = [];
  
          foreach ($varsNewObj as $values) {
              if (is_string($values) &amp;&amp; $values != null) {
                  var_dump('New Values: ' . $values);
              }
              if (is_array($values)) {
                  foreach ($values as $value) {
                      if (is_string($value) &amp;&amp; $value != null) {
                          //var_dump($value);
                      }
                      if (is_array($value)) {
                          foreach ($value as $v) {
                              if ($v != null) {
                                  //var_dump($v);
                              }
                          }
                      }
                  }
              }
          }
  </code></pre>
  
  <p>What the code above does is to get every string that is needed for comparison from the new object. The same principle can be applied to the $oldObj, however I am puzzled on how to do the comparison later on as what I have in mind seem that doesn't work.</p>