How to compare the two arrays in php?-php Tutorial

Source: Internet
Author: User
Tags php compare
How does php compare whether two arrays are equal to two arrays? $ aarray (aaa, bbb, ddd, aaa); $ barray (aaa, ddd, aaa, bbb ); to determine whether the two arrays are equal, the premise is that they cannot be sorted using built-in functions such as sort. If you must use a built-in function, which sort function is the fastest? If you are interested, you can see the following question in the example: how to compare the two arrays in a number php to see if they are equal
There are two arrays
$ A = array ('AAA', 'BBB ', 'ddd', 'AAA ');

$ B = array ('AAA', 'ddd ', 'AAA', 'BBB ');

To determine whether the two arrays are equal, the premise is that they cannot be sorted using built-in functions such as sort.

If you must use a built-in function, which sort function is the fastest?



If you are interested, you can refer to the following question in sequence: find the largest continuous set in a number array.
For example, the maximum continuous set of [,] is [,] instead.
[, 45] The maximum continuous set is [, 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
  Count ($ temp1 ))? $ Temp2: $ temp1;}; return $ temp3;} var_dump (newarray ($ a); echo"
"; Var_dump (newarray ($ B); echo"
"; Var_dump (newarray ($ c); // $ c cannot be returned correctly, because $ c may have 3, 4, 7, 8, 13, and 14 types?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.