Last active
October 13, 2015 13:18
-
-
Save LogansUA/3070de7b25e780b0a022 to your computer and use it in GitHub Desktop.
Recursive deleting fields by pattern
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 | |
/** | |
* Recursive deleting fields by pattern | |
* | |
* @param array $array Haystack | |
* @param array $pattern Pattern | |
*/ | |
public function deleteFields(&$array, $pattern) | |
{ | |
foreach ($array as $index => &$row) { | |
$inArray = in_array($index, $pattern, true); | |
if ($inArray || !is_array($array[$index])) { | |
if ($inArray) { | |
unset($array[$index]); | |
} | |
continue; | |
} | |
$this->deleteFields($array[$index], $pattern); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment