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 2014 Markus 6,050
Recognized Expert Expert
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.
code green 1,726
Recognized Expert Top Contributor
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??
code green 1,726
Recognized Expert Top Contributor
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($re move,'',$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 checking to see if the result has any 1s
in it (if so, the arrays are different). This seems to be faster than
comparing each bit of the two original arrays one at a time. But I
still have to iterate over each element of the array, and I'd like to
|
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 application.
I tried bcmp / a loop for comparison, but it seems they are very slow
compared to comparing longs...Any ideas?
I tried splitting the array into longs and comparing, but then
I face the high endian/low endian problem on some machines.
|
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 expression to return true as both arrays are
identically the same but it keeps returning false. Any info on how to solve
this problem will be appreciated.
|
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
Console.WriteLine( x1.Equals(x2) ); // false
Console.WriteLine( x1.GetLength(0) == 0 ); // true
| |
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 I do
|
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 1 to
9, but probably not all 9 integers.
MyArray1 = 1,2,3,5,6,7,8
MyArray2 = 1,4,6,7
I would need the answers to be arrays too:
|
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 dictionary keys, based on
their content, not their identity. Is this feasible using the
arrays directly, or do I need to wrap them in a struct that
handles GetHashCode and Equal? If so, is such a wrapper
present in the standard class library?
|
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 the immediate problems I am having first and try to figure the rest out myself.
Basically I need to compare the contents of a directory, with the contents of a series of 'csv' files, when those two match it will trigger some moving of the contents of...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |