The difference is that db_fetch_array() returns an array, and db_fetch_object() returns an object. Depending on the use case, you may need this or that.
It seems, at least considering the snippet you provided, they really are - with a change in syntax, as you mentioned, - interchangeable for your use case.
Edit
Drupal db_fetch_object() and db_fetch_array() are inherited from PHP *_fetch_object and *_fetch_array : Drupal just abstracts specific versions of the PHP database, so the Drupal developer does not need to worry about which database is used in the backend.
So, the same reasons that they both exist in PHP are the same reasons that they exist in Drupal. They provide flexibility for developers: in some cases of use arrays are required, some require objects.
In the core of Drupal, db_fetch_object() is much more preferable than db_fetch_array() : you can see how each of them is used in the kernel by going to each page of the API function and clicking on the n header of the call functionname function.
The reason for this shift towards db_fetch_object is mainly the preference and ease of maintenance: fewer characters say $object->property than say $object['property'] . A lot of code style in Drupal is based on a multi-year agreement.
You can use any of them, but consider whether it makes sense, semantically, that your data be an object or an array. For example, if you want to use many functions of a PHP array (e.g. array_merge() , which does not have a simple analog object), you can select a release agreement and use db_fetch_array() .
Other things being equal, *_fetch_object() is identical to *_fetch_array in terms of speed, but the received object from the first takes up a bit more memory than the resulting array from the last.
user113292
source share