mysqli_fetch_array的第二个参数

时间:2022-09-13 20:13:16

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.

我找到了答案:这个可选参数是一个常量,表示应该从当前行数据生成什么类型​​的数组。此参数的可能值是常量MYSQLI_ASSOC,MYSQLI_NUM或MYSQLI_BOTH。

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

我还想知道是否有任何不利之处?即使它被认为是可选的。

1 个解决方案

#1


4  

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

将第二个参数留空与使用默认值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.

此外,如果您正在为ajax请求提供响应,您可能希望减少要返回的响应的大小 - MYSQLI_BOTH将创建一个两倍于其他两个选项的数组。

#1


4  

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

将第二个参数留空与使用默认值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.

此外,如果您正在为ajax请求提供响应,您可能希望减少要返回的响应的大小 - MYSQLI_BOTH将创建一个两倍于其他两个选项的数组。