You are here

function notifications_array_filter in Notifications 7

Same name and namespace in other branches
  1. 6.4 notifications.module \notifications_array_filter()

Filter elements in an array of arrays/objects that match some condition

Parameters

$array: Data array to be filtered.

$filter: Array of field => value pairs

$reverse: Reverse filter, return elements that don't match

File

./notifications.module, line 929
Notifications module

Code

function notifications_array_filter($array, $filter, $reverse = FALSE) {
  if (!$filter) {
    return $array;
  }
  foreach ($array as $key => $data) {
    $compare = is_object($data) ? (array) $data : $data;
    $match = count(array_intersect_assoc($filter, $compare)) == count($filter);
    if ($match && $reverse || !$match && !$reverse) {
      unset($array[$key]);
    }
  }
  return $array;
}