drupal_map_assoc($array, $function = NULL)
drupal/includes/common.inc, line 1870
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.
$array A linear array.
$function A name of a function to apply to all values before output.
| Name | Description |
|---|---|
| Input validation | Functions to validate user input. |
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;
}
}