corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Merging Arrays


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP Merging Arrays
Laney
Member

Registered: 6th May 03
Location: Leeds
User status: Offline
16th Nov 07 at 11:07   View User's Profile U2U Member Reply With Quote

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
16th Nov 07 at 11:09   View User's Profile U2U Member Reply With Quote

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
16th Nov 07 at 11:20   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
16th Nov 07 at 11:26   View Garage View User's Profile U2U Member Reply With Quote

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
16th Nov 07 at 12:15   View User's Profile U2U Member Reply With Quote

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
17th Nov 07 at 14:02   View User's Profile U2U Member Reply With Quote

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.

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Computer Problem PeteMTBer Geek Day 31 2997
31st Mar 03 at 20:10
by Gareth.O
 
photo help - just a quicky koolkorsa General Chat 11 189
14th Dec 03 at 19:01
by koolkorsa
 
I think this New Vauxhall looks sweet as fcuk1 Martyn General Chat 39 524
7th Apr 04 at 12:25
by Tom
 
C Programming luca2020 General Chat 14 1174
18th Jul 04 at 22:17
by Ian
 
Anyone know PHP? Bit of help needed... liamC Geek Day 38 1430
24th Nov 06 at 23:02
by MarkPW
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Merging Arrays 29 database queries in 0.0328171 seconds