Skip to content

Instantly share code, notes, and snippets.

@gabrielstuff
Created February 25, 2014 00:37
Show Gist options
  • Save gabrielstuff/9200288 to your computer and use it in GitHub Desktop.
Save gabrielstuff/9200288 to your computer and use it in GitHub Desktop.
Recursive check php
private function recursiveCheck($array)
{
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $key => $current) {
$keyValid = array('section', 'block', 'text', 'item');
if(in_array($key, $keyValid) && $key !== 0 && $this->is_assoc($current)){
//error_log('key: '.$key);
$prevValue = $iterator->getInnerIterator()->offsetGet( $key );
$iterator->getInnerIterator()->offsetUnset($key);
$iterator->getInnerIterator()->offsetSet( $key, (object) Array($prevValue));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment