Reputation: 2016
plz anyone help me. I want to merge the subarrays. I have associative array to merge in php like below.but the arrays were flatter. I tried to adapt the code, but unfortunately without success. Here my example :
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
)
)
And i have to Generate like below.
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
)
)
Upvotes: 1
Views: 40
Reputation:
Try this
$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);
Upvotes: 3