php如何合并数组中的key相同的子数组 10
$arr=array('0'=>array('platfrom'=>'2','account'=>'wei','country'=>'France','amount_to...
$arr = array(
'0'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'10',
'order_number'=>'3'
),
'1'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'20',
'order_number'=>'5'
),
'2'=>array(
'platfrom'=>'1',
'account'=>'wei',
'country'=>'中国',
'amount_total'=>'20',
'order_number'=>'10'
),
'3'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'中国',
'amount_total'=>'20',
'order_number'=>'6'
),
'4'=>array(
'platfrom'=>'2',
'account'=>'yong',
'country'=>'France',
'amount_total'=>'20',
'order_number'=>'5'
),
);
如何合并数组中的这两个数组,其中'amount_total'、'order_number'的值两个数组累加!
'0'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'10',
'order_number'=>'3'
),
'1'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'20',
'order_number'=>'5'
),
需要整个$arr进行处理。
不能用太多的foreach 展开
'0'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'10',
'order_number'=>'3'
),
'1'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'20',
'order_number'=>'5'
),
'2'=>array(
'platfrom'=>'1',
'account'=>'wei',
'country'=>'中国',
'amount_total'=>'20',
'order_number'=>'10'
),
'3'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'中国',
'amount_total'=>'20',
'order_number'=>'6'
),
'4'=>array(
'platfrom'=>'2',
'account'=>'yong',
'country'=>'France',
'amount_total'=>'20',
'order_number'=>'5'
),
);
如何合并数组中的这两个数组,其中'amount_total'、'order_number'的值两个数组累加!
'0'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'10',
'order_number'=>'3'
),
'1'=>array(
'platfrom'=>'2',
'account'=>'wei',
'country'=>'France',
'amount_total'=>'20',
'order_number'=>'5'
),
需要整个$arr进行处理。
不能用太多的foreach 展开
展开全部
遍历 然后逻辑处理下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-05-19
展开全部
像这个样子:
1
2
3
4
array(
['pid'] => 6,
['title']=> '/thumb_525d615760eb0.jpg,/thumb_525d615708f2d.jpg,/thumb_525d615699a77.jpg'
)
你的第一个值一直是6吗?还是都叠加在一起,变成666?
如果是就一个6的话,可以这样:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$arr = array(3) {
[0] => array(2) {
["pid"] => string(1) "6"
["title"] => string(24) "/thumb_525d615760eb0.jpg"
}
[1] => array(2) {
["pid"] => string(1) "6"
["title"] => string(24) "/thumb_525d615708f2d.jpg"
}
[2] => array(2) {
["pid"] => string(1) "6"
["title"] => string(24) "/thumb_525d615699a77.jpg"
}
}
//以上是你自己的,
//加上我的::
$new_arr = array();
foreach($arr as $key=>$value){
for($i = 0;$i <= count_array($value);$i++){
$new_arr[$i] = .$value[$i];
}
}
这个$new_arr数组里面就把数据整合好了
?>
1
2
3
4
array(
['pid'] => 6,
['title']=> '/thumb_525d615760eb0.jpg,/thumb_525d615708f2d.jpg,/thumb_525d615699a77.jpg'
)
你的第一个值一直是6吗?还是都叠加在一起,变成666?
如果是就一个6的话,可以这样:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$arr = array(3) {
[0] => array(2) {
["pid"] => string(1) "6"
["title"] => string(24) "/thumb_525d615760eb0.jpg"
}
[1] => array(2) {
["pid"] => string(1) "6"
["title"] => string(24) "/thumb_525d615708f2d.jpg"
}
[2] => array(2) {
["pid"] => string(1) "6"
["title"] => string(24) "/thumb_525d615699a77.jpg"
}
}
//以上是你自己的,
//加上我的::
$new_arr = array();
foreach($arr as $key=>$value){
for($i = 0;$i <= count_array($value);$i++){
$new_arr[$i] = .$value[$i];
}
}
这个$new_arr数组里面就把数据整合好了
?>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询