Skip to content
Advertisement

The second parameter of mysqli_fetch_array

I have code like this:

mysqli_fetch_array($result)

I do not seem to have any errors with this, but all samples that I have seen online have a second parameter like this:

mysqli_fetch_array($result, MYSQLI_ASSOC)

Edit:

I found answer: This optional parameter is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.

I still would like to know if there is any disadvantages to not including? even though it is considered optional.

Advertisement

Answer

Leaving the 2nd parameter blank is the same as using the default value, MYSQLI_BOTH

If you write any code which loops through the indices of the returned array, you may run into problems with the default value – in that case, you would need to specify which type you need.

Also, if you’re serving responses to ajax requests, you might want to cut down on the size of the response you’re returning – MYSQLI_BOTH will create an array twice as large as either of the other two options.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement