过滤掉数组中的对象

Working within php, I am passed an array of objects ( $terms ):

array(15) {
  [0]=>
  object(WP_Term)#341 (10) {
    ["term_id"]=>
    int(263)
    ["name"]=>
    string(15) "Moo"
    ["slug"]=>
    string(15) "moo"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(263)
    ["taxonomy"]=>
    string(9) "my_topics"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(0)
    ["count"]=>
    int(29)
    ["filter"]=>
    string(3) "raw"
  }
  [1]=>
  object(WP_Term)#342 (10) {
    ["term_id"]=>
    int(264)
    ["name"]=>
    string(10) "Bark"
    ["slug"]=>
    string(10) "bark"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(264)
    ["taxonomy"]=>
    string(9) "my_topics"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(0)
    ["count"]=>
    int(17)
    ["filter"]=>
    string(3) "raw"
  }
  [2]=>
  object(WP_Term)#343 (10) {
    ["term_id"]=>
    int(281)
    ["name"]=>
    string(16) "Meow"
    ["slug"]=>
    string(16) "meow"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(281)
    ["taxonomy"]=>
    string(9) "my_topics"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(266)
    ["count"]=>
    int(2)
    ["filter"]=>
    string(3) "raw"
  }
  [3]=>
  object(WP_Term)#344 (10) {
    ["term_id"]=>
    int(282)
    ["name"]=>
    string(19) "Tweet"
    ["slug"]=>
    string(19) "tweet"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(282)
    ["taxonomy"]=>
    string(9) "my_topics"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(266)
    ["count"]=>
    int(4)
    ["filter"]=>
    string(3) "raw"
  }
  [4]=>
  object(WP_Term)#345 (10) {
    ["term_id"]=>
    int(772)
    ["name"]=>
    string(8) "Chirp"
    ["slug"]=>
    string(8) "chirp"
    ["term_group"]=>
    int(0)
    ["term_taxonomy_id"]=>
    int(772)
    ["taxonomy"]=>
    string(9) "my_topics"
    ["description"]=>
    string(0) ""
    ["parent"]=>
    int(0)
    ["count"]=>
    int(3)
    ["filter"]=>
    string(3) "raw"
  }

}

In my real array, instead of [4], there are [14]...but that shouldn't matter because I can't rely on targeting by number.

If an object within the array contains "slug" value of "meow", I want to filter that object out and produce a new array with the rest of the objects in tact.

I need to exclude a specific object which has a specific value, in the array. My approach is to use 'array_filter' Here's where I am stuck (I feel like I'm so close but traversing arrays of objects can give me a hard time):

$refinedterms = array_filter($terms, function($obj){
  echo objTEST;
  var_dump($obj);
  foreach($obj->WP_Term as $wpTermObj){
    echo wpTermObjTEST;
    var_dump($wpTermObj);
      foreach ($wpTermObj->slug as $slug) {
        echo slugTEST;
        var_dump($slug);
          if ($slug == 'meow') return false;
      }
  }
  return true;
});

The echos and var_dumps are in place to help me debug. I feel like the fourth line is where something is a miss. Thank you in advance for any assistance, it is very much appreciated.

It is as simple as:

$new_array = array_filter(
    $terms, 
    function($v) { return $v->slug !== 'meow'; }
);

Basically your function boils down to how does array_filter work.

in array_filter you have two arguments.

$array, $callback

The $array variable contains an array you wish to filter.
The $callback is a function you wish to perform for each element, which will return a boolean value. True if keep, false if discard.

The array_filter function itself will loop over each and every element and pass the current element to the callback function.

In basis the array_filter function performs this:

$keep = [];
foreach($array as $item) {
    if($callback($item)) {
         $keep[] = $item;
    }
}
return $keep;

Thus in your callback method you only need to evaluate if the current passed on item matches your criteria. If it does, you can return true. If it doesn't return false.

$matches = array_filter($terms, function($item) {
   return $item->slug != 'meow';
});

Then the matches array will only be filled with items that match the criteria that causes the callback function to return true

$cats = array_filter($terms, function($item) {
   return $item->slug == 'meow';
});

$birds = array_filter($terms, function($item) {
   return $item->slug == 'tweet';
});

$raining_dogs_and_cats = array_filter($terms, function($item) {
   return $item->slug == 'bark' || $item->slug == 'meow';
});