From 952d7eb120ffcb7a722fd136ab103e270bbddd60 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 3 Jul 2015 18:15:44 -0700 Subject: [PATCH] CRM_Utils_Array::rekey() --- CRM/Utils/Array.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 66af443f11..a2d16088d8 100644 --- 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; + } + } -- 2.25.1