Exclude one array from the other
<p>I have these two arrays, they have ID [3 and 4] as common and ID [10] as difference. I only need the item with ID [10]</p>

<pre><code>&lt;?php

$usergroups = array();
$usergroups[] = array("id" =&gt; 3, "name" =&gt; "Parish 3");
$usergroups[] = array("id" =&gt; 4, "name" =&gt; "Parish 4");

$u= (object) $usergroups;
var_dump($u);


echo '&lt;hr /&gt;';


$featuredgroups = array();
$featuredgroups [] = array("id" =&gt; 3, "name" =&gt; "Parish 3");
$featuredgroups [] = array("id" =&gt; 4, "name" =&gt; "Parish 4");
$featuredgroups [] = array("id" =&gt; 10, "name" =&gt; "Parish 10");

$fg = (object) $featuredgroups;
var_dump($fg);

  $filtered = array_diff($featuredgroups, $usergroups);
  var_dump($filtered); //returns empty result
?&gt;
</code></pre>

<p>How do I filter out the featured from  the users? I have tried this</p>

<pre><code>$filtered = array();
foreach($u as $uu)
{
   $ug = (object) $uu;
   foreach($fg as $ff)
   {
      $fgr = (object) $ff;
      if($fgr-&gt;id != $ug-&gt;id)
         echo "&lt;br&gt;---".$fgr-&gt;name;  //am supposed to add this to filtered
   }
}
</code></pre>

<p>and it's printing out</p>

<pre><code>---Parish 4
---Parish 10
---Parish 3
---Parish 10
</code></pre>

<p>instead of just 'Parish 10' which is the difference.</p>

<h2>Update</h2>

<p>For some reason, <code>array_diff</code>as suggested in the answer did not work. This only worked for linear/1-dimensional array. I tried it with multidimensional array, like the one in the question, it didn't work</p>

<pre><code>  $filtered = array_diff($featuredgroups, $usergroups);
  var_dump($filtered); //returns empty result
</code></pre>
