0

初始数组:

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”在 Desired Output 中的数组一样。

我不知道该做什么或从哪里开始。请帮忙!

4

1 回答 1

0

好的,您正在处理数组,因此您可能需要使用修改数组的函数。您很可能还需要一个foreach循环来遍历数组。辅助变量也可能有用。

它类似于儿童玩具,他们将物体插入各种形状。只需将值相互匹配即可。如果它们合适,则合并它们。只有当你不关心学习它是困难的。

于 2013-02-09T02:36:40.507 回答