PHP compare array

后端 未结 17 1791
萌比男神i
萌比男神i 2020-11-28 12:19

Is there anyway to compare arrays in php using an inbuilt function, short of doing some sort of loop?

$a1 = array(1,2,3);
$a2 = array(1,2,3);

if (array_are_         


        
17条回答
  •  隐瞒了意图╮
    2020-11-28 12:58

    As far as I can tell, there isn't a single built-in function that'll do it for you, however, something like:

    if (count($a) == count($b) && (!count(array_diff($a, $b))) {
      // The arrays are the same
    }
    

    Should do the trick

提交回复
热议问题