How to quickly find the same elements in two arrays

Source: Internet
Author: User
How to quickly find the same elements in two arrays?
For example I have two arrays of
1, (' csdn ', ' php ', ' ASP ', ' MSDN ', ' C # ', ' Java ', ' jsp ', ' VB ')
2, (' Javajia ', ' asp ', ' Java ', ' source ', ' C # ', ' Delphi ', ' JSP ', ' VC + + ')

Quickly find the same elements in two arrays, to be fast and not to traverse each one, because there are thousands of elements.
As above two arrays, the result is (' ASP ', ' Java ', ' C # ', ' JSP ')

100 points to the King! Thanks first!!



------Solution--------------------

You try the regular expression!

If there are other needs, please leave a message!
------Solution--------------------
PHP Code
$a =array (' csdn ', ' php ', ' ASP ', ' MSDN ', ' C # ', ' Java ', ' jsp ', ' VB '), $b =array (' Javajia ', ' asp ', ' Java ', ' source ', ' C # ', ' Delphi ', ' JSP ', ' VC + ');p Rint_r (Array_intersect ($a, $b));
------Solution--------------------
Upstairs positive solution!
------Solution--------------------
Find the intersection of two arrays
PHP Code
$a =array (' csdn ', ' php ', ' ASP ', ' MSDN ', ' C # ', ' Java ', ' jsp ', ' VB '), $b =array (' Javajia ', ' asp ', ' Java ', ' source ', ' C # ', ' Delphi ', ' JSP ', ' VC + ');p Rint_r (Array_intersect ($a, $b));
------Solution--------------------
discuss

PHP Code

$a =array (' csdn ', ' php ', ' ASP ', ' MSDN ', ' C # ', ' Java ', ' jsp ', ' VB ');
$b =array (' Javajia ', ' asp ', ' Java ', ' source ', ' C # ', ' Delphi ', ' JSP ', ' VC + ');

Print_r (Array_intersect ($a, $b));


------Solution--------------------
Explore

PHP Code


$a =array (' csdn ', ' php ', ' ASP ', ' MSDN ', ' C # ', ' Java ', ' jsp ', ' VB ');
$b =array (' Javajia ', ' asp ', ' Java ', ' source ', ' C # ', ' Delphi ', ' JSP ', ' VC + ');

Print_r (Array_intersect ($a, $b));



Efficiency don't know how

------Solution--------------------
Computes the intersection of two arrays
------Solution--------------------
Only need to take the same value, you can use Array_intersect () if the hyphen name also needs to be compared with ARRAY_INTERSECT_ASSOC ()
------Solution--------------------
With this function, system functions are much more efficient than custom.

Explore

PHP Code


$a =array (' csdn ', ' php ', ' ASP ', ' MSDN ', ' C # ', ' Java ', ' jsp ', ' VB ');
$b =array (' Javajia ', ' asp ', ' Java ', ' source ', ' C # ', ' Delphi ', ' JSP ', ' VC + ');

Print_r (Array_intersect ($a, $b));



Efficiency don't know how

------Solution--------------------
1 Floor Positive Solution
------Solution--------------------
I want to catch points of the 3 floor is too sharp ... Positive solution
If it's C + + I've got a sharper way.
------Solution--------------------
3 floor is the solution AH ~ ~ also study
------Solution--------------------
3 floor to the force, study.
------Solution--------------------
I also come to the dictation again: Array_intersect ()


Haha, remember ....
  • 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.