Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Is there any way to merge arrays like so:
$array1[0];
$array1[1];
$array1[2];
$array1[3];
$array2[2];
$array2[3];
$array2[4];
$array2[5];
$array3=array(0,1,2,3,4,5);
So it lists the keys from $array1 and $array2 within another array.
Any ideas?
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Ps.
$array3=array_merge($array1,$array2);
$array3=array(0,1,2,3,2,3,4,5);
Which isn't what I'm looking for
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
Does it not work if you just add one array to another.
So $array1 + $array2?
Can't remember if that works or not......
|
Ian
Site Administrator
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
What is wrong with 0,1,2,3,2,3,4,5?
You want them distinct? Or you want values not keys?
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by Ian
What is wrong with 0,1,2,3,2,3,4,5?
You want them distinct? Or you want values not keys?
Distinct keys, yes.
array_unique() seems to do the job Why isn't there a merge function that overwrites 
|
Paul_J
Member
Registered: 6th Jun 02
Location: London
User status: Offline
|
I have no idea in php...
but in asp.net you could write a function that would take all elements of one array (or as many as you require) and put them in another array, then take the elements of another array, and check if it doesn't exist, then add, otherwise don't... and you'd get a distinct list of the merged arrays.
|
|