Answer the question
In order to leave comments, you need to log in
How to filter multidimensional array?
$array1 = array(
array(
"id" => 123,
"title" => "aaa"),
array(
"id" => 456,
"title" => "bbb"),
array(
"id" => 789,
"title" => "ccc"),
array(
"id" => 101,
"title" => "ddd")
);
$array2 = array(123, 789);
$array2 = array(
array(
3 => 123),
array(
4 => 456)
);
Answer the question
In order to leave comments, you need to log in
$ids = array_map(function($n) {
return array_values($n)[0];
}, $array2);
$array1 = array_filter($array1, function($n) use($ids) {
return in_array($n['id'], $ids);
});
The task is trivial and there are many ways to solve it.
What exactly does not work in your solution?
you can use array_filter
$result = array_filter($array1, function ($item) use ($array2) {
return in_array($item['id'], $array2);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question