Programatically delete taxonomy terms Drupal 7

By calling function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL), an array of all term objects is returned. Extra parameters can be added to the function to select all items belonging to a particular parent or limit depth of the tree.

By calling function taxonomy_term_delete($tid), a new db_transaction() starts and the taxonomy object and all its children are deleted from the taxomy_term_data and taxonomy_term_hierarchy tables. As a taxonomy term is an entity which has attached fields, all attached field data is also deleted. Finally, the function clears all static cache variables for terms by using taxonomy_terms_static_reset().


$tree = taxonomy_get_tree($vid);
  foreach($tree as $key => $val){
    taxonomy_term_delete($val->tid);
}


$vids = array(6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  
foreach($vids as $vid) {
  $tree = taxonomy_get_tree($vid);
  foreach($tree as $key => $val){
    taxonomy_term_delete($val->tid);
  }
}