Drupal set key for return result of an assoc db query

My questions were too obvious. That is literally all the fetchAllAssoc() method is meant to do for you. (I always try to use it to do what the \PDO::FETCH_ASSOC parameter does—make each row of the result an array rather than an object—and walk away thinking it is useless. No, its precise use is for setting the key of the whole result set array!)

-    return $terms_query->execute()->fetchAll(PDO::FETCH_ASSOC);
+    return $terms_query->execute()->fetchAllAssoc('tid', PDO::FETCH_ASSOC);

cleantaxonomy [3311325-bulk-delete-unused-underused-terms]$ gc -m “Switch to indexing results by term ID

The previous index was just a zero-based key; this works the same as that arbitrary listing but allows us to get the term entity IDs with a simple array_keys.”

See also: