Skip to content

Instantly share code, notes, and snippets.

@LogansUA
Last active October 13, 2015 13:18
Show Gist options
  • Save LogansUA/3070de7b25e780b0a022 to your computer and use it in GitHub Desktop.
Save LogansUA/3070de7b25e780b0a022 to your computer and use it in GitHub Desktop.
Recursive deleting fields by pattern
<?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