473,498 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using function array_intersect_key

zorgi
431 Recognized Expert Contributor
I have a question but not a problem.

I have 2 arrays.

Expand|Select|Wrap|Line Numbers
  1. $array_1 = array("a", "b");
  2. $array_2 = array("a" => "x1", "b" => "x2", "c" => "x3");
  3.  
Is there php function that would return array("a" => "x1", "b" => "x2") if passed $array_1 and $array_2 or I have to write it. Looked at the manual and couldn't find it.

Thanks
Sep 24 '09 #1
6 1941
Dormilich
8,658 Recognized Expert Moderator Expert
you don’t need a whole new function…
Expand|Select|Wrap|Line Numbers
  1. array_intersect_key($array_2, array_flip($array_1));
Sep 24 '09 #2
code green
1,726 Recognized Expert Top Contributor
Try array_intersect_key() for this one
array array_intersect_key ( array array1, array array2 [, array ...] )

array_intersect_key() returns an array containing all the values of array1 which have matching keys that are present in all the arguments.
But you will need to array_flip() $array1 to make values the key. So...
Expand|Select|Wrap|Line Numbers
  1. array_intersect_key($array2,array_filp($array1);
..I think
Sep 24 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
@code green
I’ve tested that, it works.
Sep 24 '09 #4
zorgi
431 Recognized Expert Contributor
Excellent

Thank you
Sep 24 '09 #5
code green
1,726 Recognized Expert Top Contributor
Dormilich. You pipped me by one minute. But same solution.
Sep 24 '09 #6
Dormilich
8,658 Recognized Expert Moderator Expert
it’s the obvious solution, after all.
Sep 24 '09 #7

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

Similar topics

28
20270
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
1
567
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
3
23992
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
6548
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
3999
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
3
5310
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
14
2091
by: B Williams | last post by:
I am stuck on an assignment that uses classes and functions. I am receiving numerous errors when I try to run a test program to see if I wrote it correctly. Can someone please point me in the right...
2
1613
by: Tugrul HELVACI | last post by:
I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String; fPersonSurName : String; fPersonAge : Integer; published property PersonName : String...
2
3296
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
0
7126
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
7005
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
7210
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...
1
6891
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...
0
5465
agi2029
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,...
0
4595
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...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
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...

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.