comparing arrays in php, without caring for the order

前端 未结 5 769
借酒劲吻你
借酒劲吻你 2020-12-10 03:42

I have two arrays, $a and $b here, and need to check if they contain exactly the same elements (independently of the order). I am thinking of using

if (sizeo         


        
5条回答
  •  被撕碎了的回忆
    2020-12-10 04:18

    The accepted answer fails to account for duplicates. Here is my take

    public function sameElements($a, $b)
    {
       sort($a);
       sort($b);
       return $a == $b;
    }
    

提交回复
热议问题