From c447d3e31b42f2612a7db46ee723b20ad069f38e Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 19 Feb 2007 15:19:58 +0000 Subject: added filter_keys --- it.class | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/it.class b/it.class index 1dad9d7..459691e 100644 --- a/it.class +++ b/it.class @@ -256,6 +256,22 @@ function replace($replacements, $string, $p = array()) return $result; } +/** + * Extract key => value pairs from assoc array by key + * @param $array array to filter + * @param $keys array of keys to keep + */ +function filter_keys($array, $keys) +{ + $result = array(); + $keep = array_flip($keys); + + foreach ($array as $key => $val) + if (isset($keep[$key])) + $result[$key] = $val; + + return $result; } +} ?> -- cgit v1.2.3