Iterate through all children of an element I have a Drupal code below:

function myid_create_template($form, &amp;$form_state){ 
    $form['myid_templates_editor']['#access'] = TRUE;    
    foreach (element_children($form['myid_templates_editor']) as $child1)   {
        $form['myid_templates_editor'][$child1]['#access'] = TRUE;

    }     
    return $form;
}


This code iterate to the first child only of an element, but not the child with degree 2 or more. How will I iterate it to all child/grandchild of the element?
A simple recursive function will do the trick:

function allow_access(&amp;$root_element) {
  $root_element['#access'] = TRUE;
  foreach (element_children($root_element) as $key) {
    allow_access($root_element[$key]);
  }
}
allow_access($form);