Same name and namespace in other branches
- 4.7.x includes/common.inc \drupal_map_assoc()
- 5.x includes/common.inc \drupal_map_assoc()
- 6.x includes/common.inc \drupal_map_assoc()
- 7.x includes/common.inc \drupal_map_assoc()
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.
@result An associative array.
Parameters
$array: A linear array.
$function: The name of a function to apply to all values before output.
Related topics
14 calls to drupal_map_assoc()
- aggregator_form_feed in modules/
aggregator.module - aggregator_settings in modules/
aggregator.module - archive_page in modules/
archive.module - Menu callback; lists all nodes posted on a given date.
- forum_admin_configure in modules/
forum.module - Implementation of hook_settings
- node_admin_nodes in modules/
node.module - Generate the content administration overview.
File
- includes/
common.inc, line 1605 - Common functions that many Drupal modules will need to reference.
Code
function drupal_map_assoc($array, $function = NULL) {
if (!isset($function)) {
$result = array();
foreach ($array as $value) {
$result[$value] = $value;
}
return $result;
}
elseif (function_exists($function)) {
$result = array();
foreach ($array as $value) {
$result[$value] = $function($value);
}
return $result;
}
}