function drush_map_assoc

8.0.x drush.inc drush_map_assoc($array, $function = NULL)
6.x drush.inc drush_map_assoc($array, $function = NULL)
7.x drush.inc drush_map_assoc($array, $function = NULL)
5.x drush.inc drush_map_assoc($array, $function = NULL)
master drush.inc drush_map_assoc($array, $function = NULL)

Form an associative array from a linear array.

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.

3 calls to drush_map_assoc()
drush_config_export in commands/core/config.drush.inc
Command callback: Export config to specified directory (usually sync).
drush_config_import in commands/core/config.drush.inc
Command callback. Import from specified config directory (defaults to sync).
drush_core_config in commands/core/core.drush.inc
Command callback. Edit drushrc and alias files.

File

includes/drush.inc, line 1733
The drush API implementation and helpers.

Code

function drush_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;
}