Forum Moderators: coopster

Message Too Old, No Replies

Array Merger

         

sebflipper

7:21 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



I have the following 2 arrays:

$array1 = array("Heading1", "Heading2", "Heading3", "Heading4", "Heading1", "Heading1"); // Note there three Heading1's

$array2 = array("DescriptionA", "DescriptionB", "DescriptionC", "DescriptionD", "DescriptionE", "DescriptionF");

Here each heading is related to the description in the array key order e.g:

Heading1 = DescriptionA
Heading2 = DescriptionB
etc...

What I am trying to do, is if there are 2 headings with the same name (as above Heading1 is in there three times) I want the heading names to merge into one, so that there will be only one Heading1, while the descriptions will merge together so that:

Heading1 = DescriptionA DescriptionE DescriptionF

Any ideas how I can achieve this, or is there a better way of doing this?

Thanks for any help!

coopster

9:33 pm on Oct 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, sebflipper.

I would probably loop through and compare, then append the value if the key already exists.