projects
/
civicrm-core.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
08c7957
)
CRM_Utils_Array::rekey()
author
Tim Otten
<totten@civicrm.org>
Sat, 4 Jul 2015 01:15:44 +0000
(18:15 -0700)
committer
Tim Otten
<totten@civicrm.org>
Tue, 14 Jul 2015 04:00:09 +0000
(21:00 -0700)
CRM/Utils/Array.php
patch
|
blob
|
blame
|
history
diff --git
a/CRM/Utils/Array.php
b/CRM/Utils/Array.php
index 66af443f11523f5c5b9e6f63b3da6f75dc8753c2..a2d16088d81e2757e3dc1a3eaccb97f8f0f520a3 100644
(file)
--- a/
CRM/Utils/Array.php
+++ b/
CRM/Utils/Array.php
@@
-887,4
+887,21
@@
class CRM_Utils_Array {
return $newRows;
}
+ /**
+ * Rewrite the keys in an array by filtering through a function.
+ *
+ * @param array $array
+ * @param callable $func
+ * Function($key, $value). Returns the new key.
+ * @return array
+ */
+ public static function rekey($array, $func) {
+ $result = array();
+ foreach ($array as $key => $value) {
+ $newKey = $func($key, $value);
+ $result[$newKey] = $value;
+ }
+ return $result;
+ }
+
}