You are here

function notifications_array_filter in Notifications 6.4

Same name and namespace in other branches
  1. 7 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

3 calls to notifications_array_filter()
notifications_custom_build_list in notifications_custom/notifications_custom.module
Retrieve list of custom subscription types true objects
notifications_ui_subscription_types in notifications_ui/notifications_ui.module
Get info about subscription types, exclude custom types
_notifications_content_type_options in notifications_content/notifications_content.module
List (enabled) subscription options for content types

File

./notifications.module, line 1123
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;
}