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 ....