如何从PHP中的多维关联转换数组到一个维度?

时间:2013-04-02 16:09:46

标签: php multidimensional-array

我有以下数组:

Array
(
    [14] => Array
        (
            [nid] => 30698
            [changed] => 15
        )

    [13] => Array
        (
            [nid] => 30697
            [changed] => 14
        )

    [12] => Array
        (
            [nid] => 30601
            [changed] => 13
        )

    [11] => Array
        (
            [nid] => 30807
            [changed] => 12
        )

    [10] => Array
        (
            [nid] => 30806
            [changed] => 11
        )

    [9] => Array
        (
            [nid] => 30808
            [changed] => 10
        )

    [8] => Array
        (
            [nid] => 30826
            [changed] => 9
        )

    [7] => Array
        (
            [nid] => 30828
            [changed] => 8
        )

    [6] => Array
        (
            [nid] => 30839
            [changed] => 7
        )

    [5] => Array
        (
            [nid] => 30838
            [changed] => 6
        )

    [4] => Array
        (
            [nid] => 30837
            [changed] => 5
        )

    [3] => Array
        (
            [nid] => 30831
            [changed] => 4
        )

    [2] => Array
        (
            [nid] => 30830
            [changed] => 3
        )

    [1] => Array
        (
            [nid] => 30827
            [changed] => 2
        )

    [0] => Array
        (
            [nid] => 30832
            [changed] => 1
        )

)

我想隐瞒它:

阵列

(
    [14] => [changed] => 15

    [13] => [changed] => 14

    [12] => [changed] => 13

    [11] => [changed] => 12

    [10] => [changed] => 11

    [9] => [changed] => 10

    [8] => [changed] => 9

    [7] => [changed] => 8

    [6] => [changed] => 7

    [5] => [changed] => 6

    [4] => [changed] => 5

    [3] => [changed] => 4

    [2] => [changed] => 3

    [1] => [changed] => 2

    [0] => [changed] => 1

)

我能为此做些什么?

1 个答案:

答案 0 :(得分:0)

您只需通过array_map()功能运行它即可去除nid值。

$result_array = array_map(function ($item) {
    unset $item['nid'];
    return $item;
}, $input_array);