Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the deduplication of two-dimensional array by PHP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces PHP how to achieve two-dimensional array deduplication, the article introduces in great detail, has a certain reference value, interested friends must read it!

Two-dimensional array deduplication

$arr = array (array ('id'= >' 2century grammatical title = > '...', 'ding'= >' 1century relegated calendar = > '...', 'url'= >'...', 'dj'= >'...'), array ('id'= >' 2Zongzhengzhengqiang = > '...', 'ding'= >' 1Zongzhengjingfang = > '1century paranormal timekeeper = >'...', 'url'= >'...'. 'dj'= >'...')) Function about_unique ($arr=array ()) {/ * treats the two-dimensional array as an one-dimensional array, then only one is left if the value of the one-dimensional array is the same, and the one-dimensional array is returned with a rearranged indexed array, and each element in the returned one-dimensional array is an associative array formed by the original key value * / $keys = array (); $temp = array () Foreach ($arr [0] as $k = > $arrays) {/ * the key value of the associative array recorded in the array * / $keys [] = $k;} / / return $keys; / * dimensionality reduction * / foreach ($arr as $k = > $v) {$v = join (",", $v); / / dimensionality reduction $temp [] = $v;} $temp = array_unique ($temp) / / remove duplicates foreach ($temp as $k = > $v) {/ * reassemble the disassembled array into an indexed array * / $temp [$k] = explode (",", $v);} / / return $temp; / * reassemble the disassembled array according to the associated array key value * / foreach ($temp as $k = > $v) {foreach ($v as $kkk= > $ck) {$data [$k] [$keys [$kkk]] = $temp [$k] [$kkk] }} return $data;} these are all the contents of the article "how to remove duplicates in two-dimensional arrays by PHP". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report