These lines from the documentation on php.net are key:
mysqli_fetch_array() is an extended version of the mysqli_fetch_row()
function. In addition to storing the data in the numeric indices of
the result array, the mysqli_fetch_array() function can also store the
data in associative indices, using the field names of the result set
as keys.
http://www.php.net/manual/en/mysqli-result.fetch-array.php
In cases where two or more columns have the same name the only way to reference the first occurence(s) of that column is by numerical index. In these cases you need mysqli_fetch_row
or mysqli_fetch_array
with either MYSQLI_BOTH
or MYSQLI_NUM
as its second argument (in procedural usage).
mysqli_fetch_assoc($result)
is just shorthand for mysqli_fetch_array($result, MYSQLI_ASSOC)
.
mysqli_fetch_object
does what you expect: It returns a row of results as an object. Use of this over mysqli_fetch_assoc
is a matter of whether an object or an array better represents the record being handled. The object can be of whatever class you want - stdClass is the default.