gpt4 book ai didi

php - 哪个更高效 PHP : array_intersect() OR array_intersect_key()

转载 作者:行者123 更新时间:2023-12-04 20:43:26 24 4
gpt4 key购买 nike

如果键和值具有相同的内容,使用键相交还是使用值相交更有效例如:

Array
(
[743] => 743
[744] => 744
[745] => 745
[746] => 746
[747] => 747
[748] => 748
)

使用具有相同值的一个或另一个在性能上是否有任何差异。类似于使用双引号或单引号的区别?

最佳答案

来自另一篇文章:I have two unordered integer arrays, and i need to know how many integers these arrays have in common

Depending on your data (size) you might want to use array_intersect_key() instead of array_intersect(). Apparently the implementation of array_intersect (testing php 5.3) does not use any optimization/caching/whatsoever but loops through the array and compares the values one by one for each element in array A. The hashtable lookup is incredibly faster than that.

关于php - 哪个更高效 PHP : array_intersect() OR array_intersect_key(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4635530/

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