Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active November 11, 2015 20:38
Show Gist options
  • Save kjbrum/a92ebd2d4fc3fded6bc2 to your computer and use it in GitHub Desktop.
Save kjbrum/a92ebd2d4fc3fded6bc2 to your computer and use it in GitHub Desktop.
Remove specified keys from an array.
<?php
/**
* Remove specified keys from an array.
*
* @param array &$array The reference to the array to be modified
* @param array $keys An array of keys to be removed
* @return void
*/
function remove_array_keys( &$array, $keys ) {
foreach( $array as $key => &$value ) {
if( is_array( $value ) ) {
remove_array_keys( $value, $keys );
} else {
if( in_array( $key, $keys ) ) {
unset( $array[$key] );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment