title: Php Yii looping and comparison through object attributes
body: <p>I'm doing a project in Yii, but i'm quite a newbie in php.
  so my problem is i need to compare two models...and check each attribute whether they are the same or not. this is basically a php problem</p>
  
  <p>i have two models say $model1 and $model2, i need to compare each attribute of each model..
  i need to compare the models like:</p>
  
  <pre><code> if ($model1-&gt;id == $model2-&gt;id){
          //do something here
   }
   if ($model1-&gt;value == $model2-&gt;value){
          //do something here
   }
  </code></pre>
  
  <p>but dynamically without really specifying the attribute id, as i want to loop and compare through each and every attribute</p>
  
  <p>i have a code here that prints each of model1's attribute:</p>
  
  <pre><code>foreach ($model1 as $key =&gt; $value) {
              echo "$key =&gt; $value";
              echo "&lt;br/&gt;";
  
  }
  </code></pre>
  
  <p>this code results to :</p>
  
  <pre><code>id =&gt; ...
  value =&gt; ...
  name =&gt; ...
  </code></pre>
  
  <p>how do i iterate through the two models and compare them? Thanks.help is very much appreciated :)</p>