简体   繁体   English

mysqli_fetch_array 的第二个参数

[英]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.此参数的可能值是常量 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.即使它被认为是可选的。

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 将创建一个数组,其大小是其他两个选项之一的两倍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM