How PHP compares two arrays for equality
There are two arrays of
$a = Array (' AAA ', ' BBB ', ' ddd ', ' aaa ');
$b = Array (' AAA ', ' ddd ', ' aaa ', ' BBB ');
How to compare whether these two arrays are equal, provided that you cannot sort using built-in functions such as sort ().
If you must use built-in functions, which sorting function is the fastest?
Interested can look at the following question: In a number array, find the largest continuous set
For example: [1,2,5,6,7,8] The largest continuous set is [5,6,7,8] rather than
[69,36,23,65,66,67,45] The largest continuous set is [65,66,67]
------Solution--------------------
$a = Array (' AAA ', ' BBB ', ' ddd ', ' aaa ');
$b = Array (' AAA ', ' ddd ', ' aaa ', ' BBB ');
$c = Array_diff ($a, $b);
Print_r ($c);//output Array ()
-----------------------------------------
$a = Array (' Aaa1 ', ' BBB ', ' ddd ', ' aaa ');
$b = Array (' AAA ', ' ddd ', ' aaa ', ' BBB ');
$c = Array_diff ($a, $b);
Print_r ($c);//output Array (' AAA1 ')
------Solution--------------------
PHP code
!--? Php$a=array (1,2,5,6,7,8); $b =array ( 69,36,23,65,66,67,45), $c =array (3,4,7,8,10,13,14), function NewArray ($arr) {$temp 1=array (); $temp 2=array (); $temp 3 = Array (); for ($i =1; $i
count ($temp 1))? $temp 2: $temp 1; }; return $temp 3;} Var_dump (NewArray ($a)); echo "
"; Var_dump (NewArray ($b)); echo "
"; Var_dump (NewArray ($c));//cannot return $c correctly, because $c may have 3 , three kinds of 4/7,8/13,14,