Check if two arrays have the same values

后端 未结 9 1318
既然无缘
既然无缘 2020-12-15 02:45
[2,5,3]    

[5,2,3]

They are equal because they have the same values, but not in the same order. Can I find out that without using a foreach loop

9条回答
  •  醉梦人生
    2020-12-15 03:21

    This is a bit late to the party but in hopes that it will be useful:

    If you are sure the arrays both only contain strings or both only contain integers, then array_count_values($a) == array_count_values($b) has better time complexity. However, user1844933's answer is more general.

提交回复
热议问题