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.

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.