gpt4 book ai didi

php - mysql_fetch_array() 引用增加速度?

转载 作者:行者123 更新时间:2023-11-29 03:50:43 24 4
gpt4 key购买 nike

http://www.securityandcaffeine.com/2008/04/03/php-mysql-and-mysql_fetch_array/

上面的文章让我很吃惊。它说:

mysql_fetch_array() - "1 – Use quotes! 1/7th of the time to get $result['2'] compared to $result[2]"

不知道这是不是真的?

最佳答案

这似乎完全是基于一种误解。看到这句话,突出我的:

1 – You are wasting speed if you reference the values, but don’t use quotes. According to Reinhold Weber’s Blog: #17: $row[’id’] is 7 times faster than $row[id]“. If you’re doing this a lot, and often… ouch.

是的,$row['id']$row[id] 快,因为 $row[id] 是一个语法错误,它试图解析一个常量,然后把它变成一个字符串,同时抛出一个通知。 但是 $row[1] $row['id'] 都是有效 并且应该执行非常相同。如果查找数字索引和查找字符串索引之间存在差异,则差异一定很小,不值得您花时间。

关于 PHP 数组实际上没有位置键但都是关联键的启示是……不是真正的新闻,因此没有广泛传播的速度问题。事实上,这个快速基准表明“数字字符串”索引很容易成为所有索引中最慢的查找:http://codepad.org/aeNJ2u3O

无论如何,您应该使用 mysql_fetch_assocmysql_fetch_row,它们分别为您提供命名(字符串索引)或未命名(数字索引)数组。通常不需要使用 _fetch_array 来获取两者。

如果您想要真实的性能数据,请针对您的用例对其进行基准测试。

关于php - mysql_fetch_array() 引用增加速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11345894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com