If you just need to return a list of of the elements in $data
which match the filtering criteria, you can use a combination of array_filter()
and array_intersect_assoc()
to do the job:
// build an array of your filtering criteria
$filter_array = array(
'user_id' => 3,
'assignment_id' => 5
);
// filter the array
$filtered_array = array_filter($data, function ($val_array) use ($filter_array) {
$intersection = array_intersect_assoc($val_array, $filter_array);
return (count($intersection)) === count($filter_array);
});
Note that you need PHP >= 5.3.0 to utilize the anonymous function as shown.