Why You Should Go To Pycon
superprofundo.com3 pointsby grobolom0 comments
ArrayHelpers::array_select_keys();
is in no way better than array_select_keys();
There is plenty wrong with the helpers file you described at the end of your post. But it's because those functions break basic programming principles, not the fact that they happen to be simple functions in a file (and most of them are not even simple). $array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
array_select_keys($array, ['a', 'b']);
array_intersect_key($array, ['a' => '', 'b' => '']); // OR
array_intersect_key($array, array_flip(['a', 'b'])); // OR
Neither are elegant. function array_select_keys(array $dict, array $keys)
{
$result = array();
foreach ($keys as $key) {
if (array_key_exists($key, $dict)) {
$result[$key] = $dict[$key];
}
}
return $result;
}