3 回答
TA贡献1784条经验 获得超2个赞
array_merge(array1,array2,....)将是你的答案。这是一个例子。
$a = [
[
'travel_plan '=>'Schengen',
'premium_price '=>'Rs 1,200'
],
[
'travel_plan '=>'Business ',
'premium_price '=>'Rs 1,300'
]
];
$b = [
[
'travel_plan '=>'Senior ',
'premium_price '=>'Rs 1,600'
]
];
$c =array_merge ($a,$b);
echo '<pre>';
print_r($c);
输出将是这样的
Array
(
[0] => Array
(
[travel_plan ] => Schengen
[premium_price ] => Rs 1,200
)
[1] => Array
(
[travel_plan ] => Business
[premium_price ] => Rs 1,300
)
[2] => Array
(
[travel_plan ] => Senior
[premium_price ] => Rs 1,600
)
)
TA贡献1864条经验 获得超2个赞
你可以试试这个方法。
$full_array = array_merge($adult_array,$children_array,$senior_array);
$result = [];
foreach($full_array as $item){
// Count how many index
if(isset($result[$item['travel_plan']])){
$result[$item['travel_plan']] += 1;
}else{
$result[$item['travel_plan']] = 1;
}
// Sum total value
if(isset($result[$item['travel_plan'].'_total'])){
$result[$item['travel_plan'].'_total'] = $result[$item['travel_plan'].'_total'] + $item['premium_price'];
}else{
$result[$item['travel_plan'].'_total'] = $item['premium_price'];
}
}
- 3 回答
- 0 关注
- 167 浏览
添加回答
举报