summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-02-12 19:37:04 +0000
committerDries Buytaert <dries@buytaert.net>2004-02-12 19:37:04 +0000
commitb5c18e8a17024d4af8b2ea508d5ded2570893f07 (patch)
tree305a4b33d3a3130d7589d70dc5166caa25f488b2 /includes
parent14b84fa2997b5e27046a70ac307a4241d724e466 (diff)
downloadbrdo-b5c18e8a17024d4af8b2ea508d5ded2570893f07.tar.gz
brdo-b5c18e8a17024d4af8b2ea508d5ded2570893f07.tar.bz2
- Patch 5592 by Goba: introduced a new function, drupal_map_assoc().
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc27
1 files changed, 27 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 82c665179..8815458be 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1158,6 +1158,33 @@ function drupal_page_footer() {
}
/**
+ * 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 passed array. The values will either be the same
+ * (if no function was specified), or the results of the function
+ * given the value.
+ *
+ * @param $array An array
+ * @param $function A name of a function to apply to all values
+ */
+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;
+ }
+}
+
+/**
* Wrapper around xml_parser_create() which extracts the encoding from the XML
* data first and sets the output encoding to UTF-8. This function should be
* used instead of xml_parser_create(), because PHP's XML parser doesn't check