php数组实现根据某个键值将相同键值合并生成新二维数组的方法
2020-12-27 07:27
标签:数组 sdn 成功 数组实现 data 要求 tps 价格 reac ———————————————— --------------------------------------------------------------------------------------------------------------------------------------- php数组实现根据某个键值将相同键值合并生成新二维数组的方法 标签:数组 sdn 成功 数组实现 data 要求 tps 价格 reac 原文地址:https://www.cnblogs.com/yehuisir/p/13032951.html源数据
$infos = array(
array(
‘a‘ => 36,
‘b‘ => ‘xa‘,
‘c‘ => ‘2015-08-28 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
),
array(
‘a‘ => 3,
‘b‘ => ‘vd‘,
‘c‘ => ‘2015-08-20 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
),
array(
‘a‘ => 6,
‘b‘ => ‘wwe‘,
‘c‘ => ‘2015-08-28 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
),
array(
‘a‘ => 36,
‘b‘ => ‘se‘,
‘c‘ => ‘2015-08-28 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
),
array(
‘a‘ => 6,
‘b‘ => ‘aw‘,
‘c‘ => ‘2015-08-28 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
),
array(
‘a‘ => 36,
‘b‘ => ‘bv‘,
‘c‘ => ‘2015-08-28 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
),
array(
‘a‘ => 12,
‘b‘ => ‘xx‘,
‘c‘ => ‘2015-08-27 00:00:00‘,
‘d‘ => ‘2015/08/438488a00b3219929282e3652061c2e3.png‘
)
);
————————————————
版权声明:本文为CSDN博主「tjg888888」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tianjingang1/article/details/98213158
处理要求:将数组中a相同的二维数组合并到一个数组中,生成一个新的数组
php
$result= array();
foreach ($infos as $key => $info) {
$result[$info[‘a‘]][] = $info;
}
print_r($result);
Array
(
[36] => Array
(
[0] => Array
(
[a] => 36
[b] => xa
[c] => 2015-08-28 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
[1] => Array
(
[a] => 36
[b] => se
[c] => 2015-08-28 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
[2] => Array
(
[a] => 36
[b] => bv
[c] => 2015-08-28 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
)
[3] => Array
(
[0] => Array
(
[a] => 3
[b] => vd
[c] => 2015-08-20 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
)
[6] => Array
(
[0] => Array
(
[a] => 6
[b] => wwe
[c] => 2015-08-28 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
[1] => Array
(
[a] => 6
[b] => aw
[c] => 2015-08-28 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
)
[12] => Array
(
[0] => Array
(
[a] => 12
[b] => xx
[c] => 2015-08-27 00:00:00
[d] => 2015/08/438488a00b3219929282e3652061c2e3.png
)
)
)
版权声明:本文为CSDN博主「tjg888888」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tianjingang1/article/details/98213158$html = ‘‘;
foreach ($result as $k => $v) {
$html .= "车牌号: ".$k."br>";
foreach ($v as $k1 => $v1){
$html .= "【".$v1[‘jl_market_name‘].‘ * ‘.$v1[‘pro_id_name‘].‘ * ‘.$v1[‘jl_order_num‘].‘ * ‘.$v1[‘num_price‘]."元】" ."br>";
}
$html .= "br>";
}
$html .= "【总数量:".$pro_id_name.‘ ‘.$all_product_num."】";
$html .= "br>";
$html .= "【总价格:".$all_product_price."元】";
return [‘code‘=>200,‘msg‘=>‘成功!‘,‘data‘=>$html,‘content‘=>$arrData[‘content‘],‘jl_name‘=>$arrData[‘jl_name‘],‘product_id‘=>$arrData[‘product_id‘]];
文章标题:php数组实现根据某个键值将相同键值合并生成新二维数组的方法
文章链接:http://soscw.com/index.php/essay/38534.html