You are here

function messaging_array_info in Messaging 6.3

Same name and namespace in other branches
  1. 6.4 messaging.module \messaging_array_info()
  2. 7 messaging.module \messaging_array_info()

Get information from an array of data

If $type and $field, return $data[$type][$field] If $type and not $field, return $data[$type] If not $type and $field, return that field indexed by type

Parameters

$data: Array of arrays with the form array( type1 => array( field1 => value11, field2 => value12, ), type2 => ... )

$type: Main index to check

$field: Field in $data[$info] to check

$default: Value to return if no data found

File

./messaging.module, line 964

Code

function messaging_array_info($data, $type = NULL, $field = NULL, $default = NULL) {
  if ($field && $type) {
    return isset($data[$type][$field]) ? $data[$type][$field] : $default;
  }
  elseif ($field) {
    $return = array();
    foreach ($data as $key => $info) {
      $return[$key] = isset($info[$field]) ? $info[$field] : $default;
    }
    return $return;
  }
  elseif ($type) {

    // The default for this case will be an array if not specified
    return isset($data[$type]) ? $data[$type] : (isset($default) ? $default : array());
  }
  else {
    return $data;
  }
}