如何合并多维数组与自己的子数组



谁来帮帮我。我想合并子数组。我在php中有关联数组要合并,如下所示。但是阵列更平坦。我试图修改代码,但不幸的是没有成功。下面是我的例子:

Array(
 [0] => Array(
        [1] => Array(
                [pid] => 1278
                [price] => 30
            )
        [2] => Array (
                [pid] => 1279
                [price] => 300
            )
    )
    [1] => Array (
        [1] => Array (
                [pid] => 1280
                [price] => 120
            ) 
        [2] => Array (
                [pid] => 1281
                [price] => 250
            )
)

我必须生成如下。

Array (
    [1] => Array (
            [pid] => 1278
            [price] => 30
        )
    [2] => Array (
            [pid] => 1279
            [price] => 300
        )
    [3] => Array (
            [pid] => 1280
            [price] => 120
        )
    [4] => Array (
            [pid] => 1281
            [price] => 250
        )
)

试试这个

$a = array(
   array(
      1 => array(
            'pid' =>  1234
            'price' => 200
         )
      2 => array(
            'pid' =>  1234
            'price' => 200
         ) 
    ),
    array(
      1 => array(
            'pid' =>  1234
            'price' => 200
         )
      2 => array(
            'pid' =>  1234
            'price' => 200
         ) 
    );
$a = call_user_func_array('array_merge',$a);
print_r($a);

相关内容

  • 没有找到相关文章