Need a list of terms from a vocabulary machine name How can I get the terms of a vocabulary using vocabulary machine name.

I have used the following code, although it works for me but I am looking for efficient methods.

$vocabulary = taxonomy_vocabulary_machine_name_load('school_courses');
$terms = taxonomy_get_tree($vocabulary-&gt;vid);
$courses = array();
foreach($terms as $term) {
    $courses[$term-&gt;tid] = $term-&gt;name;
}
What you are doing is pretty much the same as Drupal core is doing for the term reference field, so doubt you can improve the code much.

/**
 * Returns the set of valid terms for a taxonomy field.
 *
 * @param $field
 *   The field definition.
 * @return
 *   The array of valid terms for this field, keyed by term id.
 */
function taxonomy_allowed_values($field) {
  $options = array();
  foreach ($field['settings']['allowed_values'] as $tree) {
    if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
      if ($terms = taxonomy_get_tree($vocabulary-&gt;vid, $tree['parent'])) {
        foreach ($terms as $term) {
          $options[$term-&gt;tid] = str_repeat('-', $term-&gt;depth) . $term-&gt;name;
        }
      }
    }
  }
  return $options;
}