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
8 1991
Post the code you have tried. Use code tags.
- <?
-
$array1=array("++Hello how are you 20000901",
-
"++Hows work 20010201",
-
"++Am doing great 30089254");
-
$array2=array("-+Hows work 20010201",
-
"-+I like PHP 2657656",
-
"-+Am doing great 30089254");
-
$arry3=array_diff($array1,$array2);
-
print_r($arry3);
-
?>
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.
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]
Actually I have remove that -+ and ++ and then compare but how do I remove that??
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?
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??
Can I create a singly linked list for comparing the arrays?If yes how to do it??
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?? - $rep=array("-+");
-
foreach($array1 as $array) {
-
$x=str_replace($rep,"",$array);
-
array_push($a,$array);
-
}
-
$repl=array("++");
-
foreach($array2 as $array) {
-
$y=str_replace($repl,"",$array);
-
array_push($b,$array);
-
}
-
$c=array_merge($a,$b);
-
$d=array_unique($c);
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Peter |
last post by:
Hi
how can I compare two byte arrays in VB.NET
Thank
Peter
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |