PHP中的多维数组计算

时间:2015-06-10 13:06:43

标签: php arrays multidimensional-array

我有两个数组:

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [values] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 2
                            [field_value] => Green
                            [ordering] => 0
                            [count] => 0
                        )

                    [1] => stdClass Object
                        (
                            [id] => 1
                            [field_value] => Red
                            [ordering] => 1
                            [count] => 0
                        )
                    ...
               )
          )
     [1] => stdClass Object
        (
            [id] => 2
            [values] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 2
                            [field_value] => Metall
                            [ordering] => 0
                            [count] => 0
                        )

                    [1] => stdClass Object
                        (
                            [id] => 1
                            [field_value] => Plastic
                            [ordering] => 1
                            [count] => 0
                        )
                    ...
               )
          )
)

第二阵列:

Array
(
    [0] => 2
    [1] => 6
    [2] => 5
    [3] => 3
)

我想得到输出数组:

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [values] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 2
                            [field_value] => Green
                            [ordering] => 0
                            [count] => 2
                        )

                    [1] => stdClass Object
                        (
                            [id] => 1
                            [field_value] => Red
                            [ordering] => 1
                            [count] => 6
                        )
                    ...
               )
          )
     [1] => stdClass Object
        (
            [id] => 2
            [values] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 2
                            [field_value] => Metall
                            [ordering] => 0
                            [count] => 5
                        )

                    [1] => stdClass Object
                        (
                            [id] => 1
                            [field_value] => Plastic
                            [ordering] => 1
                            [count] => 3
                        )
                    ...
               )
          )
)

如何使用array_map()array_walk_recursive()函数执行此操作?

0 个答案:

没有答案