Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Initial Array:

Array 
( 
    [0] => Array ( 
        [0] => "Kate" 
        [1] => Array ( [0] => 1 [1] => 30 [2] => 11 ) 
        [2] => "Seattle" 
    ) 
    [1] => Array ( 
        [0] => "Kate" 
        [1] => Array ( [0] => 100 [1] => 7 [2] => 55 ) 
        [2] => "Seattle" 
    ) 
    [2] => Array ( 
        [0] => "Mike" 
        [1] => Array ( [0] => 1 [1] => 2 [2] => 13 ) 
        [2] => "New York" 
    ) 
    [3] => Array ( 
        [0] => "Paul" 
        [1] => Array ( [0] => 5 [1] => 34 [2] => 9 ) 
        [2] => "Chicago" 
    ) 
    [4] => Array ( 
        [0] => "Mike" 
        [1] => Array ( [0] => 1 [1] => 30 [2] => 13 ) 
        [2] => "New York" 
    ) 
) 

Desired Output:

Array 
( 
    [0] => Array ( 
        [0] => "Kate" 
        [1] => Array ( [0] => 1 [1] => 30 [2] => 11 [3] => 100 [4] => 7 [5] => 55 ) 
        [2] => "Seattle" 
    ) 
    [1] => Array ( 
        [0] => "Mike" 
        [1] => Array ( [0] => 1 [1] => 2 [2] => 13 [3] => 30 ) 
        [2] => "New York" 
    ) 
    [2] => Array ( 
        [0] => "Paul" 
        [1] => Array ( [0] => 5 [1] => 34 [2] => 9 ) 
        [2] => "Chicago" 
    ) 
) 

I want to simplify the array based on the string value in [0] like "Kate", "Mike" or "Paul". While doing that I want to merge the arrays in [1] and make it unique, as "Mike"'s array in Desired Output.

I have no idea what to do or where to start. Please HELP!

share|improve this question
You know what you want, but you have no idea what to do or where to start? This sounds like homework. Even if it is not, you should be able to figure it out with very little effort. – Sverri M. Olsen Feb 9 at 2:19
Could you give me at least a slightest hint please? Like which function should I use? – limminho Feb 9 at 2:23

1 Answer

up vote 0 down vote accepted

Okay, you are dealing with arrays, so you may need to use functions that modify arrays. You will most likely also need a foreach loop to iterate over the array. Auxiliary variables may also be useful.

It is similar to the kid's toy where they insert objects into various shapes. Just match the values against each other. If they fit then merge them. It is only difficult if you do not care to learn it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.