任何人都可以帮助我。我想合并子阵列。 我有关联数组在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
)
)
答案 0 :(得分:2)
试试这个
$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);