Skip to content

Instantly share code, notes, and snippets.

@johnlewisdesign
Last active June 18, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnlewisdesign/e07dbb5bfb85e460a8563171ba99c193 to your computer and use it in GitHub Desktop.
Save johnlewisdesign/e07dbb5bfb85e460a8563171ba99c193 to your computer and use it in GitHub Desktop.
Find and remove an array key from a PHP array
<?php
function removeRecursive($inputArray,$delKey){
if(is_array($inputArray)){
$moreKey = explode(",",$delKey);
foreach($moreKey as $nKey){
unset($inputArray[$nKey]);
foreach($inputArray as $k=>$value) {
$inputArray[$k] = removeRecursive($value,$nKey);
}
}
}
return $inputArray;
}
$inputNew = removeRecursive($input,'keyOne,keyTwo');
print"<pre>";
print_r($inputNew);
print"</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment