Last active
November 11, 2015 20:38
-
-
Save kjbrum/a92ebd2d4fc3fded6bc2 to your computer and use it in GitHub Desktop.
Remove specified keys from an array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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