數組 去重 統計有關問題 有點難度的計算方法

來源:互聯網
上載者:User
數組 去重 統計問題 有點難度的計算方法



有一個數組 需要去重 重組數組的格式 線上討論
------解決思路----------------------


$arra = array(
0 => array(
'id' => 0,
'send_mobile'=> '13267310236',
'c_content'=>'天氣很熱注意防暑'
),
1 => array(
'id' => 1,
'send_mobile'=> '13267310285',
'c_content'=>'天氣很熱注意防暑'
),
2 => array(
'id' => 2,
'send_mobile'=> '13267310126',
'c_content'=>'天氣很熱注意防暑'
),
3 => array(
'id' => 3,
'send_mobile'=> '13267310166',
'c_content'=>'天氣防暑'
)
);

$arrb = array();

foreach ($arra as $v){
$b = $v['c_content'];
if(isset($arrb[$b]))
$arrb[$b]['send_mobile'] .= ','.$v['send_mobile'];
$arrb[$b] = isset($arrb[$b])?$arrb[$b]:$v;
}

$arrb = array_values($arrb);
print_r($arrb);
?>



------解決思路----------------------
看你那個是用c_id做區分的吧,那就直接用cid做key, $arr[$cid][] = $val
------解決思路----------------------
提示你一下 中文可以作為數組鍵

foreach ($arra as $k=>$v) { $res [$v[c_content]] = $v; }
一句話ok
------解決思路----------------------
建立個數組b,遍曆原數組a,如果遍曆項中的c_content沒有作為鍵名出現在b中,則插入一個b[c_content];否則把遍曆到的send_mobile加進去,最後再把b數組整個重新索引值排序一下。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.