473,748 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the keys of the common elements of 2 arrays ?

296 Contributor
Hello,

I have 2 arrays . One is a master array and the other slave array.

I want the keys from the master array of the values which are present in both the arrays .
Jun 6 '08 #1
5 4281
coolsti
310 Contributor
You can get the keys of an array using array_keys() function. So you can use this to get an array of array keys for each array. You can then use an array function in PHP to find the difference between the elements of these two arrays, that is, the elements present in one array which are not in the other. I cannot remember the name of this function offhand (am on my way out the door now) but take a look in the online PHP documentation under array functions. You will find everything you need there.
Jun 6 '08 #2
Markus
6,050 Recognized Expert Expert
Parent and child arrays sounds more ... professional.
;]
Jun 6 '08 #3
Markus
6,050 Recognized Expert Expert
You can then use an array function in PHP to find the difference between the elements of these two arrays, that is, the elements present in one array which are not in the other. I cannot remember the name of this function offhand (am on my way out the door now) but take a look in the online PHP documentation under array functions. You will find everything you need there.
Do you mean array_diff()
Jun 6 '08 #4
Tarantulus
114 New Member
array_diff() will give the elements which DON'T match, if I have read the OP correctly he wants the opposite of that (common elements) so I think array_intersect ($master,$slave ) is what he is after :)

(as to the master/slave/parent/child nonsense, it's all political correctness gone MAD I tells ya!)
Jun 6 '08 #5
Markus
6,050 Recognized Expert Expert
array_diff() will give the elements which DON'T match, if I have read the OP correctly he wants the opposite of that (common elements) so I think array_intersect ($master,$slave ) is what he is after :)

(as to the master/slave/parent/child nonsense, it's all political correctness gone MAD I tells ya!)
I apologise. I was just showing coolsti what he was trying to get at.
Jun 6 '08 #6

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

Similar topics

18
8005
by: lawrence | last post by:
If I'm pretty sure there is just one form on the page, can i do this? var myForm = document.forms; If I'm not sure about the form, is it safer to do this? if (document.forms) { var myForm = document.forms; // more code here........ }
3
2618
by: Amy L. | last post by:
I have a client / server application. I just want to encrypt small amounts of data 1<x<1024 characters or so. I need to load the same Key and IV in both applications. However, both the key and IV are byte arrays. What is the best way to get the keys loaded in both applications? For example in RSA you can export the keys to XML. Can you do this in Rijndael? I tried using System.Text.Encoding.UTF8 or ASCII, but this does not appear...
7
6886
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ASCIIEncoding asciiEncoder = new ASCIIEncoding();
90
10805
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in future Python versions and let dict.keys() and dict.values() both return sets instead of lists. If d is a dict, code like: for x in d.keys():
3
1994
by: utab | last post by:
Hi, there Assume that I have three vectors x,y and z that has the same number of elements. Can I use a common iterator for these three. I did it with iterx, itery and iterz but the thing I wondered was: in a for loop you can write array elements by using the same index such as; for (int i = 0 ; i!=10; ++i ) cout << x << y << z << endl; Bu
1
2278
by: bearophileHUGS | last post by:
The PEP 3100: http://www.python.org/dev/peps/pep-3100/ says: Return iterators instead of lists where appropriate for atomic type methods (e.g. dict.keys(), dict.values(), dict.items(), etc.); iter* methods will be removed. Better: make keys(), etc. return views ala Java collections??? .... To be removed:
10
1982
by: ++imanshu | last post by:
Hi, Wouldn't it be nicer to have 'in' return values (or keys) for both arrays and dictionaries. Arrays and Dictionaries looked so similar in Python until I learned this difference. Thanks, ++imanshu
2
3733
by: vikramkumar | last post by:
I have two arrays,i want to take out common elements from those two arrays in a single statement, for example ; two arrays are my @a = (1, 3 ,4 ,7 ); my @b = (2 , 3 ,6 , 7); i want to retrieve common elements that are 3 and 7 in a single statement
6
1743
by: Peter | last post by:
Hi I have a number of arrays of longs, from which I need to find a single array which only contains the values which appear in all the original arrays. For example, I could have the three arrays: 1, 3, 2, 8, 5 3, 6, 1
0
9562
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, 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...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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,...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
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...

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.