-1

这就是我现在所拥有的。

Array(
[0] => Array
    (
        [x] => 1
        [y] => 1418
        [z] => 1
    )

[1] => Array
    (
        [x] => 2
        [y] => 567
        [z] => 1
    )

[2] => Array
    (
        [x] => 3
        [y] => 2345
        [z] => 1
    )

[3] => Array
    (
        [x] => 4
        [y] => 567
        [z] => 1
    )

[4] => Array
    (
        [x] => 1
        [y] => 2134
        [z] => 2
    )

[5] => Array
    (
        [x] => 2
        [y] => 456
        [z] => 2
    )

[6] => Array
    (
        [x] => 3
        [y] => 1418
        [z] => 2
    )

[7] => Array
    (
        [x] => 4
        [y] => 676
        [z] => 2
    )
)

我想要:

Array(
[1] => Array
    (
        [1] => Array
             (
                [y] => 1418
             )
        [2] => Array
             (
                [y] => 567
             )
        [3] => Array
             (
                [y] => 2345
             )
        [4] => Array
             (
                [y] => 567
             )
    )
[2] => Array
    (
        [1] => Array
             (
                [y] => 2134
             )
        [2] => Array
             (
                [y] => 456
             )
        [3] => Array
             (
                [y] => 1418
             )
        [4] => Array
             (
                [y] => 676
             )
    )
)

现在,稍微解释一下。我想从这个数组中创建一个新数组,其中: [z] = 是第一个数组上的键 [x] = 是第二个数组上的键。

[z] 和 [x] 不必从数组中删除。

有人可以帮我怎么做吗?因为心机,不找我。特别是,我在其中创建新数组时遇到问题。

var_export:

array (
   0 => 
   array (
       'x' => '1',
       'y' => '1418',
       'z' => '1',
   ),
   1 => 
   array (
       'x' => '2',
       'y' => '567',
       'z' => '1',
   ),
   2 => 
   array (
       'x' => '3',
       'y' => '2345',
       'z' => '1',
   ),
   3 => 
   array (
       'x' => '4',
       'y' => '567',
       'z' => '1',
   ),
   4 => 
   array (
       'x' => '1',
       'y' => '2134',
       'z' => '2',
   ),
   5 => 
   array (
       'x' => '2',
       'y' => '456',
       'z' => '2',
   ),
   6 => 
   array (
       'x' => '3',
       'y' => '1418',
       'z' => '2',
   ),
   7 => 
   array (
       'x' => '4',
       'y' => '676',
       'z' => '2',
   ),
)
4

1 回答 1

1

array_chunk是您正在寻找的。

你的情况是你想要的:array_chunk($array, 4)

于 2012-12-23T02:57:16.797 回答