初始数组:
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"
)
)
期望输出:
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"
)
)
我想基于[0]中的字符串值来简化数组,如“Kate”,“Mike”或“Paul”。 在这样做时,我想合并[1]中的数组,并使其成为唯一的,作为“Mike”在期望输出中的数组。
我不知道该做什么或从哪里开始。请帮忙!
答案 0 :(得分:0)
好的,您正在处理数组,因此您可能需要使用functions that modify arrays。您很可能还需要一个foreach
循环来迭代数组。辅助变量也可能有用。
它类似于儿童玩具,它们将物体插入各种形状。只需将值相互匹配即可。如果它们合适则合并它们。只要你不在乎学习它就很难。