473,386 Members | 1,720 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,386 software developers and data experts.

Getting the keys of the common elements of 2 arrays ?

296 100+
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 4268
coolsti
310 100+
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 Expert 4TB
Parent and child arrays sounds more ... professional.
;]
Jun 6 '08 #3
Markus
6,050 Expert 4TB
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 100+
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 Expert 4TB
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
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 =...
3
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...
7
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 --------------------------------------------------- ...
90
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...
3
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...
1
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.);...
10
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,...
2
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...
6
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.