Get tid as integer from tid array returned by EntityFieldQuery I am using an EntityFieldQuery to return an array of taxonomy terms matching a provided custom field value. Using the example given in this question, I wrote a function that accepts the vocabulary, field name, and field value as arguments and returns an array of matching terms. That works perfectly, but what I really want to get back is just the integer values corresponding to the matching terms, not the array of terms.

The problem is, the data structure that's being returned looks like this:

Array
(
    [6] =&gt; stdClass Object
        (
            [tid] =&gt; 6
            [vocabulary_machine_name] =&gt; features_of_interest
        )

)


for one item, and for another: 

Array
(
    [79] =&gt; stdClass Object
        (
            [tid] =&gt; 79
            [vocabulary_machine_name] =&gt; features_of_interest
        )

)


Because of this, I can't see how to isolate the [tid] value (6 or 79 in the examples). I'd like to be able to say

$int_tid = $terms[XXX]['tid'];


but I can't get my head around whatever syntax is needed.

I've pasted my function below in case it helps. Ideally I would like to loop through the array of items, isolate each term ID value as an integer, and push it onto an array which the function would then return.

  function get_tids_from_custom_field($vocabulary, $field, $value) {

    $vocab_machine_name = taxonomy_vocabulary_machine_name_load($vocabulary);
    $query = new EntityFieldQuery();
    $query
      -&gt;entityCondition('entity_type', 'taxonomy_term')
      -&gt;entityCondition('bundle', $vocabulary)
      -&gt;propertyCondition('vid', $vocab_machine_name-&gt;vid)
      -&gt;fieldCondition($field, 'value', $value, '=');

    $terms = $query-&gt;execute();         
    $int_ids = array();

    foreach ($terms as $term) {
      dpm($term);
      array_push($int_ids, $term);
    }
    return $int_ids;
 }
The standard(?) pattern to get ids from a query over a single entity type is to use array_keys().  Something like this:

function get_tids_from_custom_field($vocabulary, $field, $value) {
  $vocab_machine_name = taxonomy_vocabulary_machine_name_load($vocabulary);
  $query = new EntityFieldQuery();
  $query
    -&gt;entityCondition('entity_type', 'taxonomy_term')
    -&gt;entityCondition('bundle', $vocabulary)
    -&gt;propertyCondition('vid', $vocab_machine_name-&gt;vid)
    -&gt;fieldCondition($field, 'value', $value, '=');

  $results = $query-&gt;execute();         

  return !empty($results['taxonomy_term']) ? array_keys($results['taxonomy_term']) : array();
}


The results array is keyed by the entity ID.