PHP Performance question: Faster to leave duplicates in array that will be searched or do array_unique?

后端 未结 3 554
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 01:53

I have code that adds values to an array. The array is later searched in another part of my code. The values that are added to the array are not necessarily unique, so it\'s

3条回答
  •  情歌与酒
    2020-12-18 02:05

    array_unique is about sqrt(n) times slower then in_array. But if you optimize the data and search again many times, it can be worth

    PS: notice that

    isset($arr[$key])

    works faster then in_array providing the same result

提交回复
热议问题