title: PHP: Checking difference between two multidim arrays
body: <p>Here's the two arrays dump:</p>
  
  <pre><code>array(2) { 
      [0]=&gt; array(7) { 
          ["id"]=&gt; string(1) "1" 
          ["shoppinglist_id"]=&gt; string(1) "1" 
          ["product_id"]=&gt; string(1) "1" 
          ["amount"]=&gt; string(1) "5" 
          ["date_added"]=&gt; string(10) "1326912709"
          ["name"]=&gt; string(7) "Tunfisk" 
          ["supplier_id"]=&gt; string(1) "2" 
      } 
      [1]=&gt; array(7) { 
          ["id"]=&gt; string(1) "2" 
          ["shoppinglist_id"]=&gt; string(1) "1" 
          ["product_id"]=&gt; string(1) "2" 
          ["amount"]=&gt; string(1) "5" 
          ["date_added"]=&gt; string(10) "1326912713" 
          ["name"]=&gt; string(3) "Lax" 
          ["supplier_id"]=&gt; string(1) "6" 
      } 
  }
  
  array(2) { 
      [0]=&gt; array(7) { 
          ["id"]=&gt; string(1) "5" 
          ["shoppinglist_id"]=&gt; string(1) "3" 
          ["product_id"]=&gt; string(1) "1" 
          ["amount"]=&gt; string(1) "5" 
          ["date_added"]=&gt; string(10) "1326912810" 
          ["name"]=&gt; string(7) "Tunfisk" 
          ["supplier_id"]=&gt; string(1) "2" 
      } 
      [1]=&gt; array(7) { 
          ["id"]=&gt; string(1) "6" 
          ["shoppinglist_id"]=&gt; string(1) "3" 
          ["product_id"]=&gt; string(1) "2" 
          ["amount"]=&gt; string(1) "5" 
          ["date_added"]=&gt; string(10) "1326912810" 
          ["name"]=&gt; string(3) "Lax" 
          ["supplier_id"]=&gt; string(1) "6" 
      } 
  }
  </code></pre>
  
  <p>I tried to do array_diff() but this does not support multi-dimensional arrays.</p>
  
  <p>So then i tried this function:</p>
  
  <pre><code>public function multidimensional_array_diff($a1,$a2)
  {
    $r = array();
  
   foreach ($a2 as $key =&gt; $second)
   {
        foreach ($a1 as $key =&gt; $first)
        {
  
              if (isset($a2[$key]))
              {
                  foreach ($first as $first_arraykey =&gt; $first_value)
                  {
  
                      foreach ($second as $second_value)
                      {
                          if ($first_value == $second_value)
                          {
                              $true = true;
                              break;   
                          }
                      }
                      if (!isset($true))
                      {
                          if($first_arraykey != "date_added" &amp;&amp; $first_arraykey != "shoppinglist_id")
                          {
                              $r[$key][$first_arraykey] = $first_value;
                          }
  
                      }
                      unset($true);
                  }
              }
              else
              {
                  $r[$key] = $first;
              }
        }
   }
    return $r;
  }
  </code></pre>
  
  <p>This does not work either, returns me differences, that arent different.</p>
  
  <p>Note as you can see it does not add to the difference array if the array key are date_added and shoppinglist_id (because, it's OK in my system that these are different).</p>
  
  <p>The above should output an empty difference array, since there are no difference between those array (if we dont look at date_added and shoppinglist_id).</p>
  
  <p>How can i make this work properly?</p>