drupal_map_assoc

Versions
4.6 – 7
drupal_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.

@result An associative array.

Parameters

$array A linear array.

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

Related topics

▾ 20 functions call drupal_map_assoc()

aggregator_block in modules/aggregator.module
Implementation of hook_block().
aggregator_form_feed in modules/aggregator.module
Generate a form to add/edit feed sources.
aggregator_settings in modules/aggregator.module
Implementation of hook_settings().
archive_browse_form in modules/archive.module
Generate a form that retrieves archives for a certain date.
contact_admin_settings in modules/contact.module
Settings tab. Using a form rather than hook_settings().
expand_date in includes/form.inc
Roll out a single date element.
form_builder in includes/form.inc
Adds some required properties to each form element, which are used internally in the form api. This function also automatically assigns the value property from the $edit array, provided the element doesn't already have an assigned value.
forum_admin_configure in modules/forum.module
Implementation of hook_settings
forum_block in modules/forum.module
Implementation of hook_block().
node_configure in modules/node.module
Menu callback; presents general node configuration options.
node_search in modules/node.module
Implementation of hook_search().
node_types_configure in modules/node.module
Menu callback; presents each node type configuration page.
poll_form in modules/poll.module
Implementation of hook_form().
search_settings in modules/search.module
Menu callback; displays the search module settings page.
statistics_block in modules/statistics.module
Implementation of hook_block().
statistics_settings in modules/statistics.module
Implementation of hook_settings().
system_view_general in modules/system.module
update_selection_page in ./update.php
user_block in modules/user.module
Implementation of hook_block().
_comment_per_page in modules/comment.module
Return an array of "comments per page" settings from which the user can choose.

Code

includes/common.inc, line 1162

<?php
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;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.