如何提取数组?

时间:2014-06-23 03:47:54

标签: php arrays extract

我有一个简单的数组:

Array (
        [1] => 36
        [2] => 8
        [3] => 16
        [4] => 49
        [5] => 17
        [6] => 19
        [7] => 13
        [8] => 18
        [9] => 34
        [10] => 22
        [11] => 11
        [12] => 92
        [13] => 14
        [14] => 12
        [15] => 20
        [16] => 95
        [17] => 23
        [18] => 15
    )

我想将数组转换为:

Array
(
    [0] => Array
        (
            [0] => 36
            [1] => 8
        )

    [1] => Array
        (
            [0] => 16
            [1] => 49
        )

    [2] => Array
        (
            [0] => 17
            [1] => 19
        )

    [3] => Array
        (
            [0] => 13
            [1] => 18
        )

    [4] => Array
        (
            [0] => 36
            [1] => 8
        )

    [5] => Array
        (
            [0] => 34
            [1] => 22
        )

    [6] => Array
        (
            [0] => 11
            [1] => 92
        )

    [7] => Array
        (
            [0] => 14
            [1] => 12
        )

    [8] => Array
        (
            [0] => 20
            [1] => 95
        )

    [9] => Array
        (
            [0] => 23
            [1] => 15
        )

)

我该怎么办?给我一些线索。谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用array_chunk()来实现此目标:

$new_array_format = array_chunk($original_array, 2);