溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用PHP實現(xiàn)對多維數(shù)組去重

發(fā)布時間:2021-03-19 17:01:33 來源:億速云 閱讀:263 作者:Leah 欄目:開發(fā)技術

這期內(nèi)容當中小編將會給大家?guī)碛嘘P使用PHP實現(xiàn)對多維數(shù)組去重,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

具體如下:

<?php
$str = '{
  "status": 0,
  "result": [
    {
      "hostName": "楊新",
      "pcode2": "41675441",
      "email": "xin.yang@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "楊新",
      "pcode2": "41675441",
      "email": "xin.yang@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "中信國安科技控股有限公司",
      "pcode2": "9730284461",
      "email": "liuxiao@gakj.xx.com",
      "selfName": "邵兵"
    },
    {
      "hostName": "中信國安科技控股有限公司",
      "pcode2": "9730284461",
      "email": "liuxiao@gakj.xx.com",
      "selfName": "邵兵"
    },
    {
      "hostName": "劉惠",
      "pcode2": "64068956",
      "email": "huijie.liu@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "劉惠",
      "pcode2": "64068956",
      "email": "huijie.liu@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "劉凱南",
      "pcode2": "14818360",
      "email": "kainan.liu_3@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "劉凱南",
      "pcode2": "14818360",
      "email": "kainan.liu_3@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "宋緯奇",
      "pcode2": "62947142",
      "email": "weiqi.song@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "宋緯奇",
      "pcode2": "62947142",
      "email": "weiqi.song@xx.cn",
      "selfName": "邵兵"
    }
  ],
  "content_type": "application/json"
}';
$res = json_decode($str,true);
echo 'num: '.count($res['result']);
print_r($res['result']);
echo "</br></br></br>";
$rrr = $res['result'];
$serializeArrs = array_map('serialize',$rrr);
$uniqueArrs = array_unique($serializeArrs);
$unserializeArrs = array_map('unserialize',$uniqueArrs);
print_r($unserializeArrs);
echo "</br></br></br>";
echo json_encode($unserializeArrs);
exit;

運行結果:

num: 10Array ( [0] => Array ( [hostName] => 楊新 [pcode2] => 41675441 [email] => xin.yang@xx.cn [selfName] => 邵兵 ) [1] => Array ( [hostName] => 楊新 [pcode2] => 41675441 [email] => xin.yang@xx.cn [selfName] => 邵兵 ) [2] => Array ( [hostName] => 中信國安科技控股有限公司 [pcode2] => 9730284461 [email] => liuxiao@gakj.xx.com [selfName] => 邵兵 ) [3] => Array ( [hostName] => 中信國安科技控股有限公司 [pcode2] => 9730284461 [email] => liuxiao@gakj.xx.com [selfName] => 邵兵 ) [4] => Array ( [hostName] => 劉惠 [pcode2] => 64068956 [email] => huijie.liu@xx.cn [selfName] => 邵兵 ) [5] => Array ( [hostName] => 劉惠 [pcode2] => 64068956 [email] => huijie.liu@xx.cn [selfName] => 邵兵 ) [6] => Array ( [hostName] => 劉凱南 [pcode2] => 14818360 [email] => kainan.liu_3@xx.cn [selfName] => 邵兵 ) [7] => Array ( [hostName] => 劉凱南 [pcode2] => 14818360 [email] => kainan.liu_3@xx.cn [selfName] => 邵兵 ) [8] => Array ( [hostName] => 宋緯奇 [pcode2] => 62947142 [email] => weiqi.song@xx.cn [selfName] => 邵兵 ) [9] => Array ( [hostName] => 宋緯奇 [pcode2] => 62947142 [email] => weiqi.song@xx.cn [selfName] => 邵兵 ) )


Array ( [0] => Array ( [hostName] => 楊新 [pcode2] => 41675441 [email] => xin.yang@xx.cn [selfName] => 邵兵 ) [2] => Array ( [hostName] => 中信國安科技控股有限公司 [pcode2] => 9730284461 [email] => liuxiao@gakj.xx.com [selfName] => 邵兵 ) [4] => Array ( [hostName] => 劉惠 [pcode2] => 64068956 [email] => huijie.liu@xx.cn [selfName] => 邵兵 ) [6] => Array ( [hostName] => 劉凱南 [pcode2] => 14818360 [email] => kainan.liu_3@xx.cn [selfName] => 邵兵 ) [8] => Array ( [hostName] => 宋緯奇 [pcode2] => 62947142 [email] => weiqi.song@xx.cn [selfName] => 邵兵 ) )


{"0":{"hostName":"\u6768\u65b0","pcode2":"41675441","email":"xin.yang@xx.cn","selfName":"\u90b5\u5175"},"2":{"hostName":"\u4e2d\u4fe1\u56fd\u5b89\u79d1\u6280\u63a7\u80a1\u6709\u9650\u516c\u53f8","pcode2":"9730284461","email":"liuxiao@gakj.xx.com","selfName":"\u90b5\u5175"},"4":{"hostName":"\u5218\u60e0","pcode2":"64068956","email":"huijie.liu@xx.cn","selfName":"\u90b5\u5175"},"6":{"hostName":"\u5218\u51ef\u5357","pcode2":"14818360","email":"kainan.liu_3@xx.cn","selfName":"\u90b5\u5175"},"8":{"hostName":"\u5b8b\u7eac\u5947","pcode2":"62947142","email":"weiqi.song@xx.cn","selfName":"\u90b5\u5175"}}

上述就是小編為大家分享的使用PHP實現(xiàn)對多維數(shù)組去重了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI