public function testArraySelectKeys() { $list = ['a' => 1, 'b' => 2, 'c' => 3]; $expect = ['a' => 1, 'b' => 2]; $this->assertEquals($expect, Arrays::selectKeys($list, ['a', 'b'])); }
/** * Selects a list of keys from an array, returning a new array with only the * key-value pairs identified by the selected keys, in the specified order. * * Note that since this function orders keys in the result according to the * order they appear in the list of keys, there are effectively two common * uses: either reducing a large dictionary to a smaller one, or changing the * key order on an existing dictionary. * * @param $dict array Dictionary of key-value pairs to select from. * @param $keys array List of keys to select. * * @return array Dictionary of only those key-value pairs where the key was * present in the list of keys to select. Ordering is * determined by the list order. * @group util * * @deprecated */ function array_select_keys(array $dict, array $keys) { return \Packaged\Helpers\Arrays::selectKeys($dict, $keys); }