How does array_udiff() work?

前端 未结 1 1165
粉色の甜心
粉色の甜心 2021-01-26 22:04

Here\'s the code, it\'s very simple:

 1,),
    (object)array( \'id\' => 4,),
    (object)array( \'id\'          


        
相关标签:
1条回答
  • 2021-01-26 22:52

    The way array_udiff() actually produces its result is of course an implementation detail and subject to change. So while what I say might be true right now, you must not rely on it.

    For instance, if you need to use an old version of PHP, you might well implement a compatibility version of the function which simply compares each element of the first array against each element of the second array, discarding any that match.

    On the other hand, if you want the most performance, you would quicksort the elements of the second array, and then perform a binary search of the elements of the first array.

    PHP 5.3 seems to combine a quicksort with a linear search. It does however abort the search once it's found a larger element.

    0 讨论(0)
提交回复
热议问题