减少多维数组的维数 [英] Reduce the dimensions of a multidimensional array

查看:49
本文介绍了减少多维数组的维数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在遍历此产品信息数组以及回显每个商品的google电子商务跟踪代码的预期结果时遇到麻烦.如何将尺寸减小一倍.简而言之-

Im having trouble iterating thru this array of product information with the desired result of echoing google ecommerce tracking code for each item. How do I reduce the dimension by one. In short -

该如何处理:

Array (
    [array] => Array (
        [0] => Array (
            [product_id] => 7
            [prod_count] => 1
            [price] => 19.99
        )
        [1] => Array (
            [product_id] => 6
            [prod_count] => 3
            [price] => 19.99
        )
        [2] => Array (
            [product_id] => 5
            [prod_count] => 2
            [price] => 19.99
        )
        [3] => Array (
            [product_id] => 4
            [prod_count] => 4
            [price] => 14.99
        )
        [4] => Array (
            [product_id] => 3
            [prod_count] => 5
            [price] => 19.99
        )
    )
 )

对此:

 Array (
            [0] => Array (
                [product_id] => 7
                [prod_count] => 1
                [price] => 19.99
            )
            [1] => Array (
                [product_id] => 6
                [prod_count] => 3
                [price] => 19.99
            )
            [2] => Array (
                [product_id] => 5
                [prod_count] => 2
                [price] => 19.99
            )
            [3] => Array (
                [product_id] => 4
                [prod_count] => 4
                [price] => 14.99
            )
            [4] => Array (
                [product_id] => 3
                [prod_count] => 5
                [price] => 19.99
            )
        )

推荐答案

该示例的明显答案是:

$array = $array['array'];

但是,假设有多个数组作为第一级:

However, assuming there are multiple arrays as level one:

$array = call_user_func_array('array_merge',$array);

这篇关于减少多维数组的维数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆