Last active
June 18, 2020 19:26
-
-
Save johnlewisdesign/e07dbb5bfb85e460a8563171ba99c193 to your computer and use it in GitHub Desktop.
Find and remove an array key from a PHP array
This file contains 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 | |
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