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!
Okay, you are dealing with arrays, so you may need to use functions that modify arrays. You will most likely also need a
foreachloop 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.