PHP compare array

后端 未结 17 1826
萌比男神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 13:18

    get the array from user or input the array values.Use sort function to sort both arrays. check using ternary operator. If the both arrays are equal it will print arrays are equal else it will print arrays are not equal. there is no loop iteration here.

    sort($a1);
    sort($a2);
    echo (($a1==$a2) ? "arrays are equal" : "arrays are not equal");
    

提交回复
热议问题