diff options
-rw-r--r-- | it.class | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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; } +} ?> |