0

I have these arrays:

$array = array();
array_push($array, array("id" => 1, "param" => "abc"));
array_push($array, array("id" => 2, "param" => "def"));
array_push($array, array("id" => 3, "param" => "ghi"));

[{"id":1,"param":"abc"},{"id":2,"param":"def"},{"id":3,"param":"ghi"}]


$search = array(1, 2);

I need to remove the object, making a search, if the $array contains $search value.

The final array should go like this:

[{"id":3,"nom":"ghi"}]

Any ideas? Thank you.

Jhonatan Sandoval
  • 1,283
  • 6
  • 24
  • 40

1 Answers1

1
$arr = array_filter($array, function($obj) use($search) {
  return !in_array($obj['id'], $search);
});

Depending on how you are using the new array, you may have to re-index it.

Community
  • 1
  • 1