Get a subset of an array based on an array of keys
问题 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; } 回答1: array_diff_key and array_intersect_key are probably what you want. 回答2: I always want this too. Like a PHP version of Underscore's pick. It's ugly and counter-intuitive, but what I