PHP多维数组合

时间:2016-01-11 23:41:01

标签: php arrays multidimensional-array

我希望能找到如何获得这种结构的帮助:

[pad] => Array
    (
        [padi] => Array
            (
                [Date] => 2016-01-01
                [Val] => 1
                [Premium] => 100
            )
        [padi] => Array
            (
                [Date] => 2016-04-01
                [Val] => 1
                [Premium] => 200
            )
        [padi] => Array
            (
                [Date] => 2016-07-01
                [Val] => 1
                [Premium] => 300
            )
        [padi] => Array
            (
                [Date] => 2016-11-01
                [Val] => 1
                [Premium] => 400
            )

    )

我有4个变量:

$p1 = array('padi' =>
                    array('Date' => $Date_0, 'Val' => $Val, 'padiPremium' => $padiPremium_0));
$p2 = array('padi' =>
                    array('Date' => $Date_1, 'Val' => $Val, 'padiPremium' => $padiPremium_1));
$p3 = array('padi' =>
                    array('Date' => $Date_1, 'Val' => $Val, 'padiPremium' => $padiPremium_1));
$p4 = array('padi' =>
                    array('Date' => $Date_1, 'Val' => $Val, 'padiPremium' => $padiPremium_1));

我已经尝试使用array_pusharray_mergearray_combine,这对我来说根本不起作用,或者只是我的做法错了。 我会很感激任何建议!

1 个答案:

答案 0 :(得分:0)

除非我误解了你,否则你试图合并4个数组:

$merged = array();
$merged[]=$p1;
$merged[]=$p2;
$merged[]=$p3;
$merged[]=$p4;

var_dump($merged);

关联数组中不能有多个相同的键(在您的情况下:padi)。