You are here

function httpbl_map_assoc in http:BL 8

Forms an associative array from a linear array. (formerly known as drupal_map_assoc, but removed from D8)

This function walks through the provided array and constructs an associative array out of it. The keys of the resulting array will be the values of the input array. The values will be the same as the keys unless a function is specified, in which case the output of the function is used for the values instead.

Parameters

$array: A linear array.

$function: A name of a function to apply to all values before output.

Return value

An associative array.

1 call to httpbl_map_assoc()
HttpblConfigForm::buildForm in src/Form/HttpblConfigForm.php
Form constructor.

File

./httpbl.module, line 458
Implements Project Honeypot's http:BL for Drupal. It provides IP-based blacklisting through http:BL and allows linking to a honeypot.

Code

function httpbl_map_assoc($array, $function = NULL) {

  // array_combine() fails with empty arrays:
  // http://bugs.php.net/bug.php?id=34857.
  $array = !empty($array) ? array_combine($array, $array) : array();
  if (is_callable($function)) {
    $array = array_map($function, $array);
  }
  return $array;
}