473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Comparing contents of two huge arrays

82
Hi,
I have two very huge arrays, the second array contains some of the elements of array1 and also different elements, both are not of the same size, have to find only the elements that are not common in both the arrays, I used array_diff but its not working can some body help me with this??

Thanks in advance
Nov 6 '08 #1
8 1991
Markus
6,050 Expert 4TB
Post the code you have tried. Use code tags.
Nov 6 '08 #2
sarega
82
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $array1=array("++Hello how are you      20000901",
  3. "++Hows work     20010201",
  4. "++Am doing great  30089254");
  5. $array2=array("-+Hows work     20010201",
  6. "-+I like PHP    2657656",
  7. "-+Am doing great    30089254");
  8. $arry3=array_diff($array1,$array2);
  9. print_r($arry3);
  10. ?>
the output should display just first element of array1 i.e ++Hello how are you 20000901
here am just giving a part of the input the actual input has more elements of similar format.
Nov 6 '08 #3
code green
1,726 Expert 1GB
The array elements all differ
[PHP]"++Hello how are you 20000901",
"++Hows work 20010201",
"++Am doing great 30089254");

"-+Hows work 20010201",
"-+I like PHP 2657656",
"-+Am doing great 30089254");[/PHP]
Nov 6 '08 #4
sarega
82
Actually I have remove that -+ and ++ and then compare but how do I remove that??
Nov 7 '08 #5
code green
1,726 Expert 1GB
but how do I remove -+ and ++
You will have to use string functions to remove.
str_replace is a simple method [PHP]$remove = array('++','-+');
str_replace($remove,'',$array);[/PHP]However this means looping through every array element before doing the array_diff.
You could use one of the array functions that employ a callback function
or array_walk().

Is it not better to strip the operator symbols off the string before inserting in the array?
Nov 7 '08 #6
sarega
82
It is not possible to remove the -+ and ++ before inserting into the array. But how do I use the array_walk?is it possible the function in array_walk to return a value??
Nov 8 '08 #7
sarega
82
Can I create a singly linked list for comparing the arrays?If yes how to do it??
Nov 8 '08 #8
sarega
82
I used the following code to display only non duplicate elements but am not getting the required results can you plz tell me the problem with this code here??
Expand|Select|Wrap|Line Numbers
  1. $rep=array("-+");
  2. foreach($array1 as $array) {
  3. $x=str_replace($rep,"",$array);
  4. array_push($a,$array);
  5. }
  6. $repl=array("++");
  7. foreach($array2 as $array) {
  8. $y=str_replace($repl,"",$array);
  9. array_push($b,$array);
  10. }
  11. $c=array_merge($a,$b);
  12. $d=array_unique($c);
Nov 9 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
1
by: Iain | last post by:
Hi Hopefully I am missing something really simple with this question, but here goes. I have two Bitarrays that I would like to compare. At the moment, I am XORing one with the other and...
12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
2
by: Raphael Iloh | last post by:
Hi all, I'm having problems comparing array objects. Take a look at this: int array1 = new int{1}; int array2 = new int{1}; Console.Writeln(array1.Equals(array2)); One would expect the above...
2
by: Robert Linder | last post by:
I am trying to compare arraylists in csharp. I setup a simple test with empty arraylists. string x1 = {}; string x2 = {}; Console.WriteLine( x1 == x2 ); // false...
18
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When...
1
by: Donald Grove | last post by:
If I have two arrays, what is a good paradigm for comparing what is in them, to determine what elements they share, or don't share? Specifically, each array could potentially contain the integers...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
3
by: erbrose | last post by:
Hello all! Newbie here, I've been tasked with a fairly intensive project here and my perl skills are still at a minimum so this post may eventually turn into a long one, but I am only going to ask...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.