In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how php multidimensional arrays remove duplicate values. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Php multi-dimensional array to remove duplicate values: 1, the use of "array_map ('serialize', $arr)" to convert the multi-dimensional array into a string in the form of an one-dimensional array; 2, use array_unique () to remove repeated values in the one-dimensional array; 3, the deduplicated one-dimensional array back to a multi-dimensional array.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php multi-dimensional array to remove duplicate values
1. Realize the function of removing repeated values from multi-dimensional array.
Function array_unique_new ($arr) {$t = array_map ('serialize', $arr); / / use the serialize () method to convert the array into an one-dimensional array in the form of a string $t = array_unique ($t); / / remove the duplicate value $new_arr = array_map (' unserialize', $t); / / then convert the newly constructed one-dimensional array back to the php value return $new_arr }
2. An array that needs to remove duplicate values
Arr = array (array ('sup_name' = >' Shanghai', 'cn_name' = >' EthylAcetate', 'en_name' = >' ethyl acetate 1', 'pinyin' = >' yisuanyizhi', 'pro_info' = >' consumables',), array ('sup_name' = >' Shanghai 2', 'cn_name' = >' EthylAcetate', 'en_name' = >' ethyl acetate 2', 'pinyin' = >' yisuanyizhi' 'pro_info' = >' consumables',), array ('sup_name' = >' Shanghai 418', 'cn_name' = >' EthylAcetate', 'en_name' = >' ethyl acetate 1', 'pinyin' = >' yisuanyizhi', 'pro_info' = >' consumables',), array ('sup_name' = >' Shanghai', 'cn_name' = >' EthylAcetate', 'en_name' = >' ethyl acetate 3' 'pinyin' = >' yisuanyizhi', 'pro_info' = >' consumables',), array ('sup_name' = >' Shanghai', 'cn_name' = >' EthylAcetate', 'en_name' = >' ethyl acetate', 'pinyin' = >' yisuanyizhi', 'pro_info' = >' consumables',), array ('sup_name' = >' Shanghai', 'cn_name' = >' EthylAcetate'') 'en_name' = >' ethyl acetate 3', 'pinyin' = >' yisuanyizhi', 'pro_info' = >' consumables',), array ('sup_name' = >' Shanghai 1', 'cn_name' = >' EthylAcetate', 'en_name' = >' ethyl acetate 4', 'pinyin' = >' yisuanyizhi', 'pro_info' = >' consumables',))
Look at the output:
3. Execute the test
$new_arr = array_unique_new ($arr); echo''; print_r ($new_arr)
Thank you for reading! This is the end of this article on "how to remove duplicate values in php multidimensional arrays". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.