tags:

views:

29

answers:

1

I wrote this function to get a subset of an array. Does php have a built in function for this. I can't find one in the docs. Seems like a waste if I'm reinventing the wheel.

function array_subset($array, $keys) {
    $result = array();
    foreach($keys as $key){
        $result[$key] = $array[$key];
    }
    return $result;
}
+3  A: 

array_diff_key and array_intersect_key are probably what you want.

prodigitalson
The function names are singular. http://www.php.net/manual/en/ref.array.phpPHP needs to clean up their naming conventions!
Keyo