主頁(yè) > 知識(shí)庫(kù) > PHP實(shí)現(xiàn)的多維數(shù)組去重操作示例

PHP實(shí)現(xiàn)的多維數(shù)組去重操作示例

熱門標(biāo)簽:哈爾濱400電話辦理到易號(hào)網(wǎng) 高識(shí)別電銷機(jī)器人 拉薩打電話機(jī)器人 智能外呼電銷系統(tǒng) h5 地圖標(biāo)注 電銷機(jī)器人-快迭智能 寶安400電話辦理 沈陽(yáng)人工智能電銷機(jī)器人公司 合肥外呼系統(tǒng)app

本文實(shí)例講述了PHP實(shí)現(xiàn)的多維數(shù)組去重操作。分享給大家供大家參考,具體如下:

最近用到了一個(gè)獲取歷史會(huì)議列表的問(wèn)題,需要去這個(gè)多維數(shù)組去重后返回返回給客戶端,這里使用了幾個(gè)php的組裝函數(shù),分享下,示例代碼如下:

?php
$str = '{
  "status": 0,
  "result": [
    {
      "hostName": "楊新",
      "pcode2": "41675441",
      "email": "xin.yang@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "楊新",
      "pcode2": "41675441",
      "email": "xin.yang@xx.cn",
      "selfName": "邵兵"
    },
    {
      "hostName": "中信國(guó)安科技控股有限公司",
      "pcode2": "9730284461",
      "email": "liuxiao@gakj.xx.com",
      "selfName": "邵兵"
    },
    {
      "hostName": "中信國(guó)安科技控股有限公司",
      "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;

運(yùn)行結(jié)果:

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] => 中信國(guó)安科技控股有限公司 [pcode2] => 9730284461 [email] => liuxiao@gakj.xx.com [selfName] => 邵兵 ) [3] => Array ( [hostName] => 中信國(guó)安科技控股有限公司 [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] => 中信國(guó)安科技控股有限公司 [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"}}

關(guān)于php的序列化的確是幾年前才使用的技術(shù),目前大家更多的是使用json_encode,且后者效率也比php的序列化高。

序列化也還是很有用的。上面的例子中主要是函數(shù)array_map()array_unique()的結(jié)合使用。

關(guān)于序列化和json編碼的效率對(duì)比的文章,可以參考 https://www.jb51.net/article/36177.htm

PS:本站還有兩款比較簡(jiǎn)單實(shí)用的在線文本去重復(fù)工具,推薦給大家使用:

在線去除重復(fù)項(xiàng)工具:
http://tools.jb51.net/code/quchong

在線文本去重復(fù)工具:
http://tools.jb51.net/aideddesign/txt_quchong

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)組(Array)操作技巧大全》、《PHP常用遍歷算法與技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《php常用函數(shù)與技巧總結(jié)》、《PHP錯(cuò)誤與異常處理方法總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • PHP二維數(shù)組的去重問(wèn)題解析
  • php二維數(shù)組合并及去重復(fù)的方法
  • php冒泡排序、快速排序、快速查找、二維數(shù)組去重實(shí)例分享
  • PHP二維數(shù)組去重算法
  • php三維數(shù)組去重(示例代碼)
  • PHP實(shí)現(xiàn)二維數(shù)組去重功能示例
  • PHP二維數(shù)組去重實(shí)例分析
  • PHP實(shí)現(xiàn)一維數(shù)組與二維數(shù)組去重功能示例
  • php數(shù)組去重實(shí)例及分析
  • PHP數(shù)組去重的更快實(shí)現(xiàn)方式分析
  • php 數(shù)組元素快速去重

標(biāo)簽:威海 泰州 梅州 山東 林芝 張家口 成都 巴中

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP實(shí)現(xiàn)的多維數(shù)組去重操作示例》,本文關(guān)鍵詞  PHP,實(shí)現(xiàn),的,多維,數(shù)組,去重,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP實(shí)現(xiàn)的多維數(shù)組去重操作示例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于PHP實(shí)現(xiàn)的多維數(shù)組去重操作示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章